Question

How to split an attribute using regular expression

  • 14 July 2021
  • 3 replies
  • 54 views

Badge +9

I am trying to split an attribute using a regular expression as there may be differences within the attribute.

 

For Example the attribute may be as AA9A or B7B

However some of the attributes are formatted as CC7 or DD6 I therefore do not want to remove the last character from these, all I need to extract is AA9 or B7.

 

Is there a way with a regular expression to search for a character, potential character and then a digit?

Or is there a better way to achieve what i am trying to do??

Thanks in advance

Andy

 


3 replies

Userlevel 3
Badge +18

There could be a simple solution but I go with StringSearcher with regex ^[A-Z]*[0-9]* or something like that.

Then you could replace the found string with the original if you want an attribute with just the A and the B in an AttributeCreator.

Userlevel 4
Badge +36

In the StringReplacer you can use the regular expression 

\D$

(all characters at the end of the attribute that are not numbers), and replace this with nothing.

 

Userlevel 5
Badge +29

I'd use the string searcher with the following REGEX

([a-zA-Z]{1,2}\d)

[a-zA-Z]{1,2} matches one or two characters (A-Z case insensitive)

\d matches one digit

(...) groups everything together

 

https://rubular.com/r/h9ItOkxPbyldAZ

Reply