0

I have some expression Like XXXX_I(YYYY) with XXXX fix I integer (1,2,3, etc) and YYYY string could be anything, any length. Is it possible d'extract just XXXX_I. Any help would be greatly appreciated.

Frenchi In LA
  • 3,139
  • 3
  • 25
  • 41

2 Answers2

2

You can use the pattern

[^(]+

or to be more strict on 4 digits and _I you can use

\d{4}_I
Drakes
  • 23,254
  • 3
  • 51
  • 94
1

You have a few options considering this is a very vague topic. A few options

[^(]*

Gets text except (until) (


.*?(?=\()

Gets text up to (


\W(.*?)\(

Gets word before (


\d{4}_I

Gets four digits I then any single character


\d{4}_I(?=\()

Gets four digits I any character then (


Which one would I use?

(?<=\W|^)\d{4}_I*?(?=\()

Is a very versatile solution which is still strict on enforcing the rules.

Or if you are using a more limited Regex flavor such as JavaScript:

(?:\W|^)\d{4}_I*?(?=\()

In which case you might have an extra space at the beginning but it would still work well.

Downgoat
  • 13,771
  • 5
  • 46
  • 69