| View previous topic :: View next topic |
| Author |
Message |
regexreplace? Guest
|
Posted: Mon Oct 08, 2007 7:49 pm Post subject: regexreplace() woes.. |
|
|
Anyone skilled or know how to work with regexreplace()?? I have a string "Login:User|||Password" and I need to get the User and Password. for example..
Login:Bob|||123
User = Bob
Password = 123
So how would I go about extracting them from a string like this? Theres a tripple pipe line in the middle of the two ("|||")...
Anyone? Thanks in advance. |
|
| Back to top |
|
 |
philz
Joined: 05 Jun 2007 Posts: 87 Location: USA
|
Posted: Mon Oct 08, 2007 8:50 pm Post subject: |
|
|
| Code: | regexmatch(inputstring,"^.+?(?=:)",login)
;takes the inputstring "Login:User|||Password" and returns
;the login in the variable "login"
;the ^ means start at the beginning of the string
;the .+? means find one or more of any character until
;the next criteria occurs
;the next criteria is (?=:) which is a lookahead assertion
regexmatch(inputstring,"(?<=:).+?(?=|||),User)
;stors the username from the inputstring and puts it
;into the variable called "user"
regexmatch(inputstring,"(?<|||).*?$",Password)
;stores the password from inputstring into the variable, "Password"
|
This is untested, but it should work.
if there is a problem it would be with my assertions. you could edit the regexmatches and use stringreplace from there to get your desired result |
|
| Back to top |
|
 |
regexreplace? Guest
|
Posted: Mon Oct 08, 2007 9:14 pm Post subject: |
|
|
| it works, thanks. And thx for the helpful comments! |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Oct 08, 2007 9:20 pm Post subject: |
|
|
| looks like I spoke too soon... I thought maybe all that was missing was the second quote mark in your second line of code.. but i guess that wasn't the issue. Its returning the 1st letter of the user in the string, thats it.. |
|
| Back to top |
|
 |
philz
Joined: 05 Jun 2007 Posts: 87 Location: USA
|
Posted: Tue Oct 09, 2007 10:04 am Post subject: |
|
|
oh DUH
the | is an either or symbol and needs to be escaped with a \
here is your new code string.
| Code: | regexmatch(inputstring,"(?<=:).+?(?=\|{3})",User)
;the {3} is saying that it must repeat the | three times |
I suggest you download titans Regex Analyzer.
That should be useful to you in learning regular expressions.
They are a VERY useful tool. |
|
| Back to top |
|
 |
Guest
|
Posted: Thu Oct 11, 2007 11:01 pm Post subject: |
|
|
| thanks it works now |
|
| Back to top |
|
 |
|