I have a string like Acc:123-456-789
and another string like -1234567, I need your help to write an expression to match digits in case there is no separator between the digits.
-*(?!\d*(?:\d*-)$)\d*$
Input strings:
Acc:123-456-789 -12323232 7894596
Desired result:
group 1 12323232
group 2 7894596
I think this ought to work:
(?<=^|\s|\s-)(\d+)(?=\s|$)
Breaking it down:
(?<=^|\s|\s-)
- A positive lookbehind that matches the start of the string, whitespace, or whitespace followed by a -
.(\d+)
- Matches and captures number sequences.(?=\s|$)
- A positive lookahead that matches whitespace or the end of the string.** Note: If you need to capture negative number sequences, replace (\d+)
with (\-?\d+)
.
Remember for use in C# that you need to escape backslashes or use the @
prefix to a string literal (@" "
).
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加