Skip to main content
Solved

String searcher in regular expressions

  • October 26, 2017
  • 7 replies
  • 44 views

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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

7 replies

redgeographics
Celebrity
Forum|alt.badge.img+60
  • Celebrity
  • 3701 replies
  • 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
Celebrity
  • 7843 replies
  • October 26, 2017

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
  • 10 replies
  • 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+60
  • Celebrity
  • 3701 replies
  • 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

 

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
  • 10 replies
  • October 26, 2017
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
  • 2252 replies
  • 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.


  • 3 replies
  • September 25, 2019

^([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