2

Trying to extract 1st match string between numbers: For example:

testsfa13.4extractthis8488.9090testssffwwww

ajfafs-sss133.6extractthis887878.222testtest522252.9thismore

So far I have the following:

[\d](.*?)[\d]

However, the match includes the numbers at the end of capture group? Any suggestions appreciated. Thank you.

PaulP
  • 37
  • 3

2 Answers2

3

If you want to extract the first match, you could start with an anchor ^ matching any char except a digit \D* and then match a digit with an optional decimal part.

^\D*\d+(?:[.,]\d+)*(\D+)\d
  • ^ Start of string
  • \D* Match 0+ times any char except a digit
  • \d+(?:[.,]\d+)* Match 1+ digits and optionally repeat a . or , and 1+ digits
  • (\D+) Capture group 1, match 1+ times any char except a digit
  • \d Match a digit

Regex demo

To prevent crossing newline boundaries:

^[^\d\n\r]*\d+(?:[,.]\d+)*([^\d\n\r]+)\d

Regex demo

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
1

try \d([A-Za-z]+)\d and get first value from returned object

https://regex101.com/r/v61exp/1

Jacek Rojek
  • 1,082
  • 8
  • 16