Skip to main content
Question

How to split an attribute using regular expression


ingalla
Contributor
Forum|alt.badge.img+10

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

jkr_wrk
Influencer
Forum|alt.badge.img+29
  • July 14, 2021

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.


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • July 14, 2021

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.

 


hkingsbury
Celebrity
Forum|alt.badge.img+53
  • Celebrity
  • July 14, 2021

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings