Skip to main content
Question

Why doesn't my regex expression work?

  • Jul 21, 2023 5:34 AM UTC
  • 8 replies
  • 82 views

williamlin98
Contributor
Forum|alt.badge.img+8

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
Supporter
Forum|alt.badge.img+14
  • Supporter
  • Jul 21, 2023 6:05 AM UTC

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+71
  • Evangelist
  • Jul 21, 2023 9:00 AM UTC

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
Evangelist
Forum|alt.badge.img+54
  • Evangelist
  • Jul 21, 2023 9:22 AM UTC

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+71
  • Evangelist
  • Jul 21, 2023 9:40 AM UTC

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
Supporter
Forum|alt.badge.img+14
  • Supporter
  • Jul 21, 2023 9:48 AM UTC

Which would look like this:

StringSearcher2Thanks, I never knew this

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


sameer
Supporter
Forum|alt.badge.img+23
  • Supporter
  • Jul 21, 2023 10:06 AM UTC

@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
Evangelist
Forum|alt.badge.img+54
  • Evangelist
  • Jul 21, 2023 10:09 AM UTC

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+8
  • Author
  • Contributor
  • Jul 23, 2023 10:05 PM UTC

Thanks for the answers everyone, helped heaps <3