REG_MATCH function in Informatica - Identify a pattern

196 Views Asked by At

Can you please help me identify a regex pattern for the below set of strings

1921 abc abc abc 1k

4320 abcs abc Apt 201b

1250 abcd Ave Apt 3c

61a abcd Ave

1b abcd Ave

39r abcd Rd

16w750 abcd Ave

abc 12a

The ask is to identify if a sentence contain a single character before, after or in between digits.

\d[A-Za-z]\d|\d[A-Za-z]|^[A-Za-z]\d

This is something I tried, but didn't work :)

Only a single character should be present.There can be many numbers.

3

There are 3 best solutions below

6
dawg On

You didn't really supply a precise definition but this does match your pattern:

\b(?=\d+[a-zA-Z][0-9]*)([0-9a-zA-Z]*)

Demo

If there is a possibility of non digits starting (which is not in your example) then use an alteration:

\b(?=(?:[a-zA-Z]\d+[a-zA-Z]*)|(?:\d+[a-zA-Z]\d*))[a-zA-Z0-9]*

Demo

1
Wiktor Stribiżew On

The REG_MATCH function needs the whole string to be matched, so you can use

REG_MATCH( subject, '.*\b\d+[a-z]\d*\b.*' )

Details:

  • .* - any zero or more characters other than line break chars as many as possible
  • \b - a word boundary
  • \d+ - one or more digits
  • [a-z] - a lowercase ASCII letter
  • \d* - zero or more digits
  • \b - a word boundary
  • .* - any zero or more characters other than line break chars as many as possible

See the regex demo.

0
Luis Colorado On

Just try

\b(\d*[a-zA-Z]\d+|\d+[a-zA-Z]\d*)\b

You will need to match it and then extract the second matching group (the middle one) You can check it here.