Skip to main content
Solved

String searcher in regular expressions


Forum|alt.badge.img

How can I separate every single word from the string e.g. “GROUND ROUND STATION 49” in String Searcher by using regular expressions? I have never used regular expressions earlier.

Expression \\s*(\\w+)\\s* can select first word “ground” but how to obtain 2nd word, 3rd word, n word in single separate columns? By trial-error-method I got the second word by applying this expression \\s+(\\w+)\\s+. However how to create more general expresion?

 

Best answer by redgeographics

The AttributeSplitter with a space as delimiter character will have the desired result without having to use regular expressions.

View original
Did this help you find an answer to your question?

7 replies

redgeographics
Celebrity
Forum|alt.badge.img+49
  • Celebrity
  • Best Answer
  • October 26, 2017

The AttributeSplitter with a space as delimiter character will have the desired result without having to use regular expressions.


takashi
Influencer
  • October 26, 2017
redgeographics wrote:

The AttributeSplitter with a space as delimiter character will have the desired result without having to use regular expressions.

I agree that the AttributeSplitter is a quick way in this case. However, if you want to learn about the usage of the StringSearcher too, try using this regex and setting Subexpression Matches List Name parameter.

 

(\w+)

Forum|alt.badge.img
  • Author
  • October 26, 2017

@redgeographics it works for me, however how can I set extracted single words into columns as output to later test this values? attributesplitter.png

 


redgeographics
Celebrity
Forum|alt.badge.img+49
vid wrote:

@redgeographics it works for me, however how can I set extracted single words into columns as output to later test this values? attributesplitter.png

 

You can use an AttributeCreator to create new attributes and fill them with the list elements

That does mean you'll need to know the max number of list elements. I'm sure there's some smart python code to achieve this dynamically but I'm not the right person to answer Python questions.

 

 


Forum|alt.badge.img
  • Author
  • October 26, 2017
redgeographics wrote:
You can use an AttributeCreator to create new attributes and fill them with the list elements

That does mean you'll need to know the max number of list elements. I'm sure there's some smart python code to achieve this dynamically but I'm not the right person to answer Python questions.

 

 

 

Thank you!

 


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • October 26, 2017

@vid

Stringsearchers can nowadays get all matches. (previously only possible by using a tcl regexp in a creator and setting the -all switch.

As @takashi pointed out, you just have to set both parameters, All Matches ad Submatches.

Submatches.part{} wil hold a list of all matches.

Of course as this case is a simple regexp (strings separated by a space) a splitter is also ok.

But for more complex regexp the splitter is of no use quickly.


^([A-Z]*)| ([A-Z]*)| ([A-Z]*)| ([A-Z]*)| ([A-Z]*)| ([A-Z]*)| ([A-Z]*)| ([A-Z]*) etc.. not sure how to get numbers to show yet


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