Link to home
Create AccountLog in
Avatar of HackLife
HackLife

asked on

vbscript regular expressions: I need to find a string that starts with asdfj= but not inclusive...

I need to find a string that starts with asdfj= but not inclusive...

basically, i need everything that follows asdfj=
Avatar of JesterToo
JesterToo
Flag of United States of America image

This can be done easily without regex...

Dim strText
Dim strSubText
Dim nPtr

   strText = 'The lazy dog jumped over asdfj=the sleeping cat"

   nPtr = Instr(strText,"asdfj=")
   If nPtr > 0 Then
      strSubText = Mid(strText,nPtr + 6)
   End If


strSubText will contain "the sleeping cat" at the end of this execution.

HTH,
Lynn
Avatar of HackLife
HackLife

ASKER

I would have to loop to find multiple instances. I wonder which one is faster.
it's multiple instances: for example:

asdfj=lskdjfasldkfj;asldkfjdslfkjlaskdjflskdjflksjdfkldjf;asdfj=johakcliekkdkdkdkdkdkdkkdkdkdkdk;asdf=kekekekekeke;
Avatar of Bob Learned
(asdfj=)([\w]+)

The parenthesis will separate this expression into 2 groups.  In that way you can find a match, and look at the group portion that you need.

Bob
The parenthesis are not working and the contents have colons, periods, newlines and such, so the \w does not work here. Thanks
Can you give me an example to test?

Bob
I've been using

The pattern = "asdfj=[^;""]*"

Right(Match, Len(Match) - Len("asdfj=")) to solve this problem.

It would be nice to combine the two into on pattern.

You can see the pattern above and what i'm looking for. Everything except semicolon and doublequotes.
Do you have some text that I can test an expression with?

Bob
I'm new to this pattern stuff, so I don't know what is a good switch if any to remove the "asdfj=" from the list of matches.
Also, what are you working on?  There might be a different way versus using regular expressions.

Bob
The information maybe classified, so I can't give you specific data.

I got my script to do what I need. I just want to do that which is mentioned above more effieciently. Instead of an expression and a left(text, instr()), I'd rather just do an expression. There is no other better way than expression because the CSV files i'm parsing are 100k and up, very very large. I tested it with csv database connections and instr() mid() and array loops. All are much much slower. Timed them using timer.

So, all I want to know is, is there are way to pull the asdfj=whatever;asdfj=againwhatever; without including the asdfj= string in the match, and without using right(text, len(text) - len(asdfj=))
ASKER CERTIFIED SOLUTION
Avatar of JesterToo
JesterToo
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer