String extract question

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: String extract question

#16 Post by aGerman » 22 May 2011 08:55

I'm surprised because I thought \s would match tabs as well.
BTW: I guess finally this should be the right syntax

Code: Select all

strPattern = "\w+_C\d+\.jpg[\s\t]+\d+[\s\t]+with[\s\t]+handwritten"

The * means that you could also omit the pattern. + means the pattern has to be matched one or more times.

Regards
aGerman

renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: String extract question

#17 Post by renzlo » 22 May 2011 16:42

yes, thanks aGerman.

renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: String extract question

#18 Post by renzlo » 23 May 2011 08:51

hi aGerman,

my source has changed. It is now like this:

Code: Select all

thisfile_c1.jpg  12345678 with handwritten
12345678 thisfile_c1.jpg  with handwritten


i tried editing the string pattern in vbs through reg ex using pipe but it won't work.

asking for your help now, thanks.

renzlo

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: String extract question

#19 Post by aGerman » 23 May 2011 10:38

Haha, I assume regex is too tricky sometimes. But however it's the only possibility to extract those strings.
Try:

Code: Select all

strPattern = "(\w+_C\d+\.jpg\s+\d+|\d+\s+\w+_C\d+\.jpg)\s+with handwritten"

This works for me even if there are tabs instead of spaces. Otherwise you have to replace \s+ with [\s\t]+ again.

Regards
aGerman

Post Reply