Sign in to follow this  
Followers 0
maxilla

StringRegExpReplace Help

19 posts in this topic

#1 ·  Posted (edited)

I have a text in the format "TeamA V. TeamB" (without quotes)

i want to split the text into two values using StringRegExpReplace like

$part1="TeamA"

$part2="TeamB"

ie part1 containts text upto "V."

part2 containts text after "V."

Also V. should be case in-sensitive(V. or v.)

please help...

Edited by maxilla

Share this post


Link to post
Share on other sites



still waiting...

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

still waiting...

First, what did you try? If you show that you put some effort into it yourself you might get more help.

Second, why not use StringSplit()?

/edit: ok, StringSplit does not work case-insensitively I think... How about third: why not use StringInStr()?)

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

i read stringregexpreplace...but dint understand..i im a newbie plz help...can anyone gimme the code?

Edited by maxilla

Share this post


Link to post
Share on other sites

i read stringregexpreplace...but dint understand..i im a newbie plz help...can anyone gimme the code?

People here will generally give you suggestions or corrections if you post what you have tried so far. Again, my suggestion would be to go through them with StringInStr (it will give you the index of a substring in another string), and then get the left part up to this index in one var, and the right part from the end of the substring in another var?


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

i read stringregexpreplace...but dint understand..i im a newbie plz help...can anyone gimme the code?

So being a noob is reason to write the code for you without an ounce of effort on your part?... I would think that would be reserved for those that show effort on a consistent basis.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

hey i tried...

$loc = StringInStr($FullText,"V.")
$partA= StringTrimLeft($FullText, $loc+1)

i got part A like this....but part B i dint get plz help

Share this post


Link to post
Share on other sites

hey i tried...

$loc = StringInStr($FullText,"V.")
$partA= StringTrimLeft($FullText, $loc+1)

i got part A like this....but part B i dint get plz help

Upload the text file you are searching... will take like 1 minute to get the code right :whistle: .

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Not atext file n all...just one line stored in a varible $Fulltext

I got location of "V." from left and using stringtrimleft to get part A

how to get location of "V." from right so that i can use stringtrimright and get part B???

Share this post


Link to post
Share on other sites

Not atext file n all...just one line stored in a varible $Fulltext

I got location of "V." from left and using stringtrimleft to get part A

how to get location of "V." from right so that i can use stringtrimright and get part B???

I hate cloak and dagger.
#include <array.au3>
$sString = 'TeamA V. TeamB'
$aArray = StringRegExp($sString, '(?s)(?i).*?(Team.)\s+V\.\s+(Team.)', 3)
_ArrayDisplay($aArray, '')
Time to start reading on what this does.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

GOD i was just giving teamA n team B as examples....there are thousands of different lines with the format partA V. partB ...plz giv a generalize solution...

how to use stringinstr and get position of "V." from right??? then i can trim it using stringtrimright na???plz help

Share this post


Link to post
Share on other sites

Not atext file n all...just one line stored in a varible $Fulltext

I got location of "V." from left and using stringtrimleft to get part A

how to get location of "V." from right so that i can use stringtrimright and get part B???

Don't use StringTrim for this, since it in your case erases parts of the string that you still need. Instead, use StringLeft for reading the left part, and StringRight or StringMid to read the right part (you will need StringLen too to know how many characters from the right side you will need).


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

GOD i was just giving teamA n team B as examples....there are thousands of different lines with the format partA V. partB ...plz giv a generalize solution...

how to use stringinstr and get position of "V." from right??? then i can trim it using stringtrimright na???plz help

Try to understand the regex, it is pretty easy in the given example.

Share this post


Link to post
Share on other sites

NO stringtrim is enough ...

$len=StringLen($fulltext) 
$loc = StringInStr($fulltext,"V.")
$locr = $len-$loc
$partA = StringTrimLeft($fulltext, $loc+1)
$partB= StringTrimRight($fulltext, $locr+1)

Thankssssssss.....

Share this post


Link to post
Share on other sites

NO stringtrim is enough ...

$len=StringLen($fulltext) 
$loc = StringInStr($fulltext,"V.")
$locr = $len-$loc
$partA = StringTrimLeft($fulltext, $loc+1)
$partB= StringTrimRight($fulltext, $locr+1)

Thankssssssss.....

Hey nice...

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

NO stringtrim is enough ...

$len=StringLen($fulltext) 
$loc = StringInStr($fulltext,"V.")
$locr = $len-$loc
$partA = StringTrimLeft($fulltext, $loc+1)
$partB= StringTrimRight($fulltext, $locr+1)

Thankssssssss.....

or if you're lazy (as i am) you could just:

Dim $thestring = 'TeamA V. TeamB',$anarray
$anarray = StringSplit($thestring,' V. ',1)
For $x = 1 to $anarray[0]
MsgBox(0,"Element " & $x,$anarray[$x])
Next

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

or if you're lazy (as i am) you could just:

Dim $thestring = 'TeamA V. TeamB',$anarray
$anarray = StringSplit($thestring,' V. ',1)
For $x = 1 to $anarray[0]
MsgBox(0,"Element " & $x,$anarray[$x])
Next
Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

Or is stringsplit already case-INsensitive? Just tried it to be sure, but it seems indeed case-INsensitive! I didn't expect this since it is mentioned nowhere in the help file... I consider this an omission :whistle:

Sorry for my last post, I only tested my own code and that worked too :P


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

Or is stringsplit already case-INsensitive? Just tried it to be sure, but it seems indeed case-INsensitive! I didn't expect this since it is mentioned nowhere in the help file... I consider this an omission :whistle:

Sorry for my last post, I only tested my own code and that worked too :P

I assumed based on the amount of data that it was being generated programatically so case would be uniform....

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

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