oshaker Posted February 23, 2010 Share Posted February 23, 2010 (edited) I have strings like this:1. abcd xx-xx-x2. abcd xx-xx-xx3. abcd xx-xx-xxxText I want to remove is in red, the rest of the string i.e. "abcd" is not fixed. I need to make them like this:abcd xx-xxWhat is the pattern I can use to achieve this? I am using StringRegExpReplace function Edited February 23, 2010 by oshaker Link to comment Share on other sites More sharing options...
99ojo Posted February 23, 2010 Share Posted February 23, 2010 (edited) Hi, although i'm quite sure that a stringregexp guru will jump the train as well: $string1 = "abcd xx-xx-x" $string2 = "abcd xx-xx-xx" $string3 = "abcd xx-xx-xxx" For $x = 1 To 3 $par = Eval ("string" & $x) MsgBox (0,Eval ("string" & $x), _mysplit ($par)) Next Func _mysplit ($string) $retstring = "" $temp = StringSplit ($string, "-", 2) For $i = 0 To UBound ($temp) - 2 If $i < UBound ($temp) - 2 Then $retstring &= $temp [$i] & "-" Else $retstring &= $temp [$i] EndIf Next Return $retstring EndFunc ;-)) Stefan Edited February 23, 2010 by 99ojo Link to comment Share on other sites More sharing options...
oshaker Posted February 23, 2010 Author Share Posted February 23, 2010 This is better: ([0-9]+\-) with count = 1 using StringRegExpReplace function Link to comment Share on other sites More sharing options...
notsure Posted February 23, 2010 Share Posted February 23, 2010 If the pattern is always the same, you can do it this way.local $string[4] local $yourstring $string[1] = "abcffd xx-xx-x" $string[2] = "abaacd xx-xx-xx" $string[3] = "aebcd xx-xx-xxx" for $i = 1 to 3 $yourstring = stringtrimright($string[$i], (stringlen($string[$i]) - stringinstr($string[$i], "-",0,2)) + 1) msgbox(1,"",$yourstring) NextBut this construction requires the string always to be :XXXXXXorwhateverherestandsrofl XX-XX- Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now