I've got some text that follows the format
text ( text + numbers | text + numbers | 2-4 digit number text)
I'm interested in extracting the 2-4 digit number from this string in C#. My regEx string is
.*?\|.*?\|([0-9][0-9][0-9]?[0-9]?)
This correctly returns whether the string matches or not, but I'm not able to extract just the digits.
I've tried calling regex.match(input).Value, but it returns the entire input.
I must be missing something - any help is appreciated :)
Your regex defines a Group
- inside parenthesis with the value you want. Using just Value
from the Match object returns the entire string that was matched for the regex.
Use regex.Match(input).Groups[1].Value for extracting the number.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.