Skip to main content
Question

Why doesn't my regex expression work?


williamlin98
Contributor
Forum|alt.badge.img+3

I am trying to extract the 1st and 4th word but it just keeps grabbing the first 4 words, I've tried without the ^ and it doesn't workregexinquirng

8 replies

tomfriedl
Contributor
Forum|alt.badge.img+13
  • Contributor
  • July 21, 2023

RegEx show you the match string. The string to extract in brackets return by the list "Subexpression Matches List Name" (Transformer Stringsearcher).


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • July 21, 2023

Use a StringSearcher. Let your regex find all words. Write all matches to a list. Item 0 of the list contains the first match (you can also write the first match to an attribute in the StringSearcher), item 3 of the list contains the fourth match.

StringSearcher


ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • July 21, 2023
geomancer wrote:

Use a StringSearcher. Let your regex find all words. Write all matches to a list. Item 0 of the list contains the first match (you can also write the first match to an attribute in the StringSearcher), item 3 of the list contains the fourth match.

StringSearcher

If using the StringSearcher, you can use the Subexpression Matches List Name and that will return just the 1st and 4th words as two list items(the items within the brackets in the regex)


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • July 21, 2023
geomancer wrote:

Use a StringSearcher. Let your regex find all words. Write all matches to a list. Item 0 of the list contains the first match (you can also write the first match to an attribute in the StringSearcher), item 3 of the list contains the fourth match.

StringSearcher

Which would look like this:

StringSearcher2Thanks, I never knew this


tomfriedl
Contributor
Forum|alt.badge.img+13
  • Contributor
  • July 21, 2023
geomancer wrote:

Which would look like this:

StringSearcher2Thanks, I never knew this

I'm writing this in the first answer ...


sameer
Contributor
Forum|alt.badge.img+16
  • Contributor
  • July 21, 2023

@williamlin98​ Attach is a workspace which I hope provides you with another alternative solution. As others have suggested, you will still need to create a list. It seems to me that the value of your attribute is separated by hyphen. If that is the case then splitting your attribute value works out better.

image


ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • July 21, 2023

You can also extract the first and fourth words within an AttributeCreator/AttributeManager using the StringFunction @SubstringRegularExpression. The 1 and 2 in these expressions refer to the 1st and 2nd match groups image

 


williamlin98
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • July 23, 2023

Thanks for the answers everyone, helped heaps <3


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