I am cleaning data where I want to detect all characters starting with 'i' or 'f' and with length between 1 and 3.
Example (ignore the meaning of the text):
- payment for i date
- payment for inv date
- payment for f
I need to catch the bold string.
This is what I have so far but it is not getting the long string inv
\s[i|f]{1}|\s[i|f]{2}|\s[i|f]{3}
CodePudding user response:
You can use this simple regex:
\b[if]\p{L}{0,2}\b
Or if you want ignore case matches then use:
\b[ifIF]\p{L}{0,2}\b
RegEx Breakup:
\b
: Word boundary[if]
: Matchi
orf
[ifIF]
: Matchi
orf
orI
orF
\p{L}{0,2}
: Match 0 to 2 unicode letters\b
: Word boundary