Skip to main content
Solved

How to practise String searcher


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+
View original
Did this help you find an answer to your question?

6 replies

redgeographics
Celebrity
Forum|alt.badge.img+49

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


david_r
Celebrity
  • 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+38
  • Influencer
  • 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
  • August 27, 2019
ebygomm wrote:

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+38
  • Influencer
  • August 27, 2019
gylona wrote:

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
  • 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.


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