You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by "PAULO LOURENCO (RE-ESI-Workflow)" <pa...@esi.pt> on 2008/12/18 15:51:28 UTC

regular expression extractor

Greetings,

 

I know this is going to look like a basic question, which I apologize
for in advance, but I'm having problems with a simple regular
expression.

Basically I want to extract a number that comes after a word and that is
followed by a space and something else. Ex:

Word 123 - more stuff

>From the previous sentence, what I want o extract is the 123, regardless
of what comes after ('-', '.', etc) knowing that the number comes always
after a word.

 

Thanks in advance!

 


Re: regular expression extractor

Posted by Serpent_Guard <bl...@gmail.com>.
Whoops, that's '[\w^\d]+'.
-- 
View this message in context: http://www.nabble.com/regular-expression-extractor-tp21074258p21086088.html
Sent from the JMeter - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: regular expression extractor

Posted by sebb <se...@gmail.com>.
On 22/12/2008, PAULO LOURENCO (RE-ESI-Workflow) <pa...@esi.pt> wrote:
> Greetings!
>
>  Let me just say that I added the \s to the end of your proposed solution:
>
> [a-zA-Z]{min,max}(\d+)
>
> To look lik:
>  [a-zA-Z]{min,max}(\d+)\s
>
>  To ensure the number is followed by a white space and everything is looking good!!!

If you refer back to my posting, you'll see that:

'[a-zA-Z]{min,max}(\d+) '

already has a space after the number...

Your original posting said the word was followed by a space, rather
than white space (which includes tab etc), otherwise I would have used
\s.

>  Thanks!
>
>
>  -----Original Message-----
>  From: sebb [mailto:sebbaz@gmail.com]
>  Sent: sábado, 20 de Dezembro de 2008 1:47
>  To: JMeter Users List
>  Subject: Re: regular expression extractor
>
>  On 19/12/2008, Serpent_Guard <bl...@gmail.com> wrote:
>  >
>  >  Whoops, that's '[\w^\d]+'.
>
>  [^\d] means all but 0-9 but [\w^\d] means \w, ^, or \d so it will
>  match more than is required.
>  The ^ only negates a class if present at the start.
>
>  This can be seen by using the demo at:
>
>  http://jakarta.apache.org/oro/demo.html
>
>  For example, try the input 'abcd12^3xyz' - '[\w^\d]+' matches in its entirety.
>
>  The original poster wrote:
>
>  > Basically I want to extract a number that comes after a word and that is
>  > followed by a space and something else. Ex:
>  >
>  > Word 123 - more stuff
>
>  If by a word you mean only alphabetic characters, then
>
>  '[a-zA-Z](\d+) '
>
>  (without the ')
>
>  should extract the digits following the last letter of a "word".
>
>  Or, if you know the min and max lengths of a word, you could use:
>
>  '[a-zA-Z]{min,max}(\d+) '
>
>
>  >  --
>  >
>  > View this message in context: http://www.nabble.com/regular-expression-extractor-tp21074258p21086104.html
>  >
>  > Sent from the JMeter - User mailing list archive at Nabble.com.
>  >
>  >
>  >  ---------------------------------------------------------------------
>  >  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  >  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  >
>  >
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


RE: regular expression extractor

Posted by "PAULO LOURENCO (RE-ESI-Workflow)" <pa...@esi.pt>.
Greetings!

Let me just say that I added the \s to the end of your proposed solution:
[a-zA-Z]{min,max}(\d+) 
To look lik:
[a-zA-Z]{min,max}(\d+)\s

To ensure the number is followed by a white space and everything is looking good!!!

Thanks!

-----Original Message-----
From: sebb [mailto:sebbaz@gmail.com] 
Sent: sábado, 20 de Dezembro de 2008 1:47
To: JMeter Users List
Subject: Re: regular expression extractor

On 19/12/2008, Serpent_Guard <bl...@gmail.com> wrote:
>
>  Whoops, that's '[\w^\d]+'.

[^\d] means all but 0-9 but [\w^\d] means \w, ^, or \d so it will
match more than is required.
The ^ only negates a class if present at the start.

This can be seen by using the demo at:

http://jakarta.apache.org/oro/demo.html

For example, try the input 'abcd12^3xyz' - '[\w^\d]+' matches in its entirety.

The original poster wrote:

> Basically I want to extract a number that comes after a word and that is
> followed by a space and something else. Ex:
>
> Word 123 - more stuff

If by a word you mean only alphabetic characters, then

'[a-zA-Z](\d+) '

(without the ')

should extract the digits following the last letter of a "word".

Or, if you know the min and max lengths of a word, you could use:

'[a-zA-Z]{min,max}(\d+) '


>  --
>
> View this message in context: http://www.nabble.com/regular-expression-extractor-tp21074258p21086104.html
>
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: regular expression extractor

Posted by sebb <se...@gmail.com>.
On 19/12/2008, Serpent_Guard <bl...@gmail.com> wrote:
>
>  Whoops, that's '[\w^\d]+'.

[^\d] means all but 0-9 but [\w^\d] means \w, ^, or \d so it will
match more than is required.
The ^ only negates a class if present at the start.

This can be seen by using the demo at:

http://jakarta.apache.org/oro/demo.html

For example, try the input 'abcd12^3xyz' - '[\w^\d]+' matches in its entirety.

The original poster wrote:

> Basically I want to extract a number that comes after a word and that is
> followed by a space and something else. Ex:
>
> Word 123 - more stuff

If by a word you mean only alphabetic characters, then

'[a-zA-Z](\d+) '

(without the ')

should extract the digits following the last letter of a "word".

Or, if you know the min and max lengths of a word, you could use:

'[a-zA-Z]{min,max}(\d+) '


>  --
>
> View this message in context: http://www.nabble.com/regular-expression-extractor-tp21074258p21086104.html
>
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: regular expression extractor

Posted by Serpent_Guard <bl...@gmail.com>.
Whoops, that's '[\w^\d]+'.
-- 
View this message in context: http://www.nabble.com/regular-expression-extractor-tp21074258p21086104.html
Sent from the JMeter - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: regular expression extractor

Posted by Serpent_Guard <bl...@gmail.com>.
I think you want '[\w+] (\d+) .+' (w/o quotes).

[\w+] - \w is a character class that matches any word character
(alphanumeric plus underscores).  '+' changes it from matching a single
character to matching one or more characters.

(\d+) - \d is a character class that matches digits.  '+' makes it match one
or more digits.

.+ - '.' matches any non-newline character.  '+' makes it match one or more
of those characters.

If you specifically don't want to allow digits in the first word, you can
change '[\w+]' to '[\w^\d]'

I'm no expert at regex, but I've been learning a lot about it lately and I'm
reasonably sure this'll do the trick.



PAULO LOURENCO (RE-ESI-Workflow) wrote:
> 
> Greetings,
> 
>  
> 
> I know this is going to look like a basic question, which I apologize
> for in advance, but I'm having problems with a simple regular
> expression.
> 
> Basically I want to extract a number that comes after a word and that is
> followed by a space and something else. Ex:
> 
> Word 123 - more stuff
> 
> From the previous sentence, what I want o extract is the 123, regardless
> of what comes after ('-', '.', etc) knowing that the number comes always
> after a word.
> 
>  
> 
> Thanks in advance!
> 
>  
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/regular-expression-extractor-tp21074258p21086078.html
Sent from the JMeter - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org