Skip to main content
Solved

How to practise String searcher

  • August 26, 2019
  • 6 replies
  • 48 views

Forum|alt.badge.img

Hello,

I want to extract from a .txt file the size of an object, it looks like: Size: 1575200 .

I am using StringSearcher to find it in the text file, the regular expression is like : Size: [\\s\\S]*$

It works well, but I want toget only the value, so 1575200 and not like Size: 1575200

Do you have any idea?

Best answer by ebygomm

If you only want the numeric value after 'Size:' you could also use the following regular expression

(?<=Size: )\d+
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.

6 replies

redgeographics
Celebrity
Forum|alt.badge.img+60
  • Celebrity
  • 3701 replies
  • August 26, 2019

What you could do after you've found the matches is use a StringReplacer to replace "Size: " with an empty string.


david_r
Celebrity
  • 8394 replies
  • August 26, 2019

You can also use the following regex:

Size: (\d+)

And specify the subexpression list name "_subs" under Advanced settings:

0684Q00000ArKCmQAN.png

You will then find the size value under "_subs{0}.part" which you can rename as you wish.


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • Best Answer
  • August 26, 2019

If you only want the numeric value after 'Size:' you could also use the following regular expression

(?<=Size: )\d+

Forum|alt.badge.img
  • Author
  • 14 replies
  • August 27, 2019

If you only want the numeric value after 'Size:' you could also use the following regular expression

(?<=Size: )\d+

Thanks! 

And what if there is not numeric value, but text. Like: SIze: Medium and I want to get only Medium?


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • August 27, 2019

Thanks!

And what if there is not numeric value, but text. Like: SIze: Medium and I want to get only Medium?

You could use \\w instead of \\d which will match any word character (letter, number, underscore)


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • 2252 replies
  • August 30, 2019

 

AS he said his regexp is ok.

He just did not "capature" his needs.

So to capture the number

Size: [\\s\\S]*$

anything between brackets is a character class. So you have space and non-spacecharacters in the class...

So regexp should be

must be Size:\\s+(\\S+)$

still not safe so make it Size:\\s+(\\d+)$

$ is end of line, so you will only grab them at the end of a line.

to get all, remove end of line assertion.

 

The captured objects are now in the sub-match part of the stringsearcher. Expose.