Skip to main content

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?

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


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.


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

(?<=Size: )\d+

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?


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)


 

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.


Reply