Jump to content

Match string help


Recommended Posts

I have strings like this:

1. abcd xx-xx-x

2. abcd xx-xx-xx

3. abcd xx-xx-xxx

Text 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-xx

What is the pattern I can use to achieve this? I am using StringRegExpReplace function

Edited by oshaker
Link to comment
Share on other sites


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))

Func _mysplit ($string)
    $retstring = ""
    $temp = StringSplit ($string, "-", 2)
    For $i = 0 To UBound ($temp) - 2
        If $i < UBound ($temp) - 2 Then 
            $retstring &= $temp [$i] & "-"
            $retstring &= $temp [$i]
    Return $retstring



Edited by 99ojo
Link to comment
Share on other sites

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)

But this construction requires the string always to be :

XXXXXXorwhateverherestandsrofl XX-XX-

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

  • Recently Browsing   0 members

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