Home > Software engineering >  RegEX match only first value
RegEX match only first value

Time:03-21

Hello in regex how can i find ONLY first two number that start with "39"?

I tried with

^(.*?)39

but it deletes the second match also. Example:

393905598787
393400048083

I want:

3905598755
3400048099

With my code, the result is this:

05598755
3400048099

The 05598755 is wrong because I have two 39s at the beginning, but I want to discard only the first 39.

CodePudding user response:

You can consume the rest of the line after you match 39 at the start of the line and use

Find What: ^39(.*)
Replace With: $1

Details:

  • ^ - start of a line
  • 39 - a fixed value
  • (.*) - Group 1 ($1): matches the rest of the line.

See the demo settings:

enter image description here

If the 39 is not at the start of the line, use ^(.*?)39(.*) and replace with $1$2.

CodePudding user response:

Try this code...

Find:^\d{2}(.*) or ^\d\d(.*)
Replace with:$1

Was working for me ...

  • Related