Jump to content

StringRegExp and ClipGet() help needed


Recommended Posts

Hello

I'm a bit stuck. Tried different variations from helpfile with no luck. How to identify if ClipGet() includes following characters: "****S?"

where *= letter(a-Z) or a number and

?=letter X or a number (0 to 9)

For example ClipGet() could be for example

- 7341S7

- 7341SX 

- D187S1

If StringRegExp(ClipGet(),'....S.') then

            MsgBox($MB_SYSTEMMODAL, "", "This is ok.")

EndIf

 

Link to comment
Share on other sites

48 minutes ago, Marc said:
$x = ClipGet()
If StringRegExp($x,'^[a-z0-9]{4}S[a-z0-9]$') then
            MsgBox(0, "", "This is ok.")
EndIf

seems to work

... StringRegExp($x,'^[A-Za-z0-9]{4}S(X|[0-9])$')

seems to work better ;).

After the S, only the letter X or a number is allowed. If only capital letters should be permitted, then you can omit a-z :

... StringRegExp($x,'^([A-Z]|\d){4}S(X|\d)$')

(the pattern can also be shortened)

Edited by Musashi
typo

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Link to comment
Share on other sites

Thanks but I need a bit of modification as I found out that actually what ClipGet() will contain is

xxxxxSx

where

x= a-zA-Z0-9

S= s or S

Total of 7 digits/letters and 5 before S/s 

I just cant get it working. Whats wrong?

$x = ClipGet()

If StringRegExp($x,'^[A-Za-z0-9]{5}s|S[A-Za-z0-9]$') then
            MsgBox(0, "Accepted", "This is ok.")
         Else
            MsgBox(0, "Denied", "This is not ok.")
EndIf

 

Link to comment
Share on other sites

As modification from the code of @Nine:

Func check($text)
    If  StringRegExp($text,"(?i)^[[:alnum:]]{5}s[\dx]$")  Then
        ConsoleWrite("+" & $text & " is ok" & @CRLF)
    Else
        ConsoleWrite("!" & $text & " is not ok" & @CRLF)
    EndIf
EndFunc   ;==>check

check("b7341S7")
check("7a341SX")
check("1D187S1")
check("xxxxxSx")

 

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Link to comment
Share on other sites

4 minutes ago, Nine said:

There is no S in there ?

Same like with this "00001BE". Sometimes code works ok but sometimes false outcome. I just dont get it why your code wont work reliably?

 

Link to comment
Share on other sites

I cannot control what you got in your clipboard, but it is working fine.  So put a ConsoleWrite like me to show the content of the clip.

Local $a = ["A7341S7","a7341sX","2D187s9", "00001BE", "3267173"]

For $s in $a
  ConsoleWrite ("With " & $s & "(" & Binary($s) & ") SRE returns " & StringRegExp($s,"(?i)^[[:alnum:]]{5}s[[:alnum:]]$") & @CRLF)
Next

 

Edited by Nine
added binary to have the exact content of the clip
Link to comment
Share on other sites

2 hours ago, Nine said:

(moving target ;))

:lol:

@USSSR : Just to make sure - The latest rule : xxxxxSx is True if x=a-zA-Z0-9 and S=s or S (total of 7 digits/letters and 5 before S/s )

1 hour ago, USSSR said:

Sometimes code works ok but sometimes false outcome. I just dont get it why your code wont work reliably?

@Nine 's code works reliably !

You could additionally remove Whitespace characters, but finally the console output will show, what is provided by ClipGet.

Local $a = ["A7341S7","a7341sX","2D187s9", "00001BE", "3267173"]
For $s in $a
    $s = StringStripWS ($s, 8)
    ConsoleWrite ("With " & $s & "(" & Binary($s) & ") SRE returns " & StringRegExp($s,"(?i)^[[:alnum:]]{5}s[[:alnum:]]$") & @CRLF)
Next

BTW : From the Help (StringRegEx) : [:alnum:] = ASCII letters and digits ( same as [^\W_] or [A-Za-z0-9] ).

   

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

I got this working with the help of you. At the end there had to be one Sleep() inserted after copying the 7 digits from the program for AutoIT/ClipGet(). Otherwise it didn't work reliably.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...