Sign in to follow this  
Followers 0
erezlevi

stringregexp help

7 posts in this topic

#1 ·  Posted (edited)

I need to write a stringregexp that will comply with the follwoing strings:

H100

H 25

H 33

H 13

so I wrote this down:

$sRegExPattern = 'H |1\d{2}'

but it doesn't work for me. I started by an H, find "space" or "1" then, any number after with 2 digit lenght. did I got it right?

I tried this also:

$sRegExPattern = 'H\s|1\d{2}' still nothing, I get an array of "H" only.

Edited by erezlevi

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I need to write a stringregexp that will comply with the follwoing strings:

H100

H 25

H 33

H 13

so I wrote this down:

$sRegExPattern = 'H |1\d{2}'

but it doesn't work for me. I started by an H, find "space" or "1" then, any number after with 2 digit lenght. did I got it right?

I tried this also:

$sRegExPattern = 'H\s|1\d{2}' still nothing, I get an array of "H" only.

Try this:

$string = "H 100"

$RegExp = StringRegExp($string, "(?i)H\s*\d{1,}", 1)

MsgBox(0, "", $RegExp[0])

:)

Edited by rasim

Share this post


Link to post
Share on other sites

Try this:

$string = "H 100"

$RegExp = StringRegExp($string, "(?i)H\s*\d{1,}", 1)

MsgBox(0, "", $RegExp[0])

:)

You can replace the '{1,}' with '+'

Share this post


Link to post
Share on other sites

You can replace the '{1,}' with '+'

Yes! You are right. :)

Share this post


Link to post
Share on other sites

well that isn't what I ment:

again, your solution will display everything that start with H and space after it and number in any LENGHT! i need it only in two digits if it is below 100 and 3 digits if it is 100 only.

H100

H 98

H 65

your solution will match H 656646464 also! and I need only H 65 from it or if it is: H100939383 the: H100 only.

Thanks.

Share this post


Link to post
Share on other sites

Hi,

#include<Array.au3>
$Test = 'H100  H   89 H 19 H100939383'
$re = StringRegExp($Test, 'H\d{3}|H\s+\d{2}',3)
_ArrayDisplay($re)

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Hi,

#include<Array.au3>
$Test = 'H100  H   89 H 19 H100939383'
$re = StringRegExp($Test, 'H\d{3}|H\s+\d{2}',3)
_ArrayDisplay($re)

Mega

Thanks Mega, but with yours H101 and H102 are getting through also, so I changed it to:

$re = StringRegExp($Test, 'H100|H\s+\d{2}',3)

Thanks,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0