Regular expression pattern 
Author Message
 Regular expression pattern

Please help someone!

I am having some difficulty forming a regular expression search pattern for
the following

<name>=<textdelimiter><any free form text including spaces><textdelimiter>

eg
Name="Matthew"
or
Name='Matthew'
or
Name="Matthew again 1.299"
or
Name = 'Matthew again 1.299     '

I am using the VBScript RegExp object, the best I've done so far is
pattern = "\w+\=\""[\w\b]+\s*\""|\w+\=\'[\w\b]+\s*\'"

but it doesn't work with examples 3 and 4

any clues from RegExp gurus would be most welcome

Thanks

root



Sun, 14 Dec 2003 21:21:31 GMT  
 Regular expression pattern
I have fiddled and twiddled, and got it to work with : <drum roll>
Pattern =
"\w+\=\""[(\w|\.|\-|\&|\#|\;|\:|\/)+\s*]*\s*\""|\w+\=\'[(\w|\.|\-|\&|\#|\;|\
:|\/)+\s*]*\s*\'"

ta da!

could anyone optimize it?

thanks for reading.

root


Quote:
> Please help someone!

> I am having some difficulty forming a regular expression search pattern
for
> the following

> <name>=<textdelimiter><any free form text including spaces><textdelimiter>

> eg
> Name="Matthew"
> or
> Name='Matthew'
> or
> Name="Matthew again 1.299"
> or
> Name = 'Matthew again 1.299     '

> I am using the VBScript RegExp object, the best I've done so far is
> pattern = "\w+\=\""[\w\b]+\s*\""|\w+\=\'[\w\b]+\s*\'"

> but it doesn't work with examples 3 and 4

> any clues from RegExp gurus would be most welcome

> Thanks

> root



Sun, 14 Dec 2003 21:52:06 GMT  
 Regular expression pattern
root says:

Quote:
>I have fiddled and twiddled, and got it to work with : <drum roll>
>Pattern =
>"\w+\=\""[(\w|\.|\-|\&|\#|\;|\:|\/)+\s*]*\s*\""|\w+\=\'[(\w|\.|\-|\&|\#|\;|\
>:|\/)+\s*]*\s*\'"

>could anyone optimize it?

How about this...

Pattern = "([^=]+)=['""](.+)['""]"

----------
Randy Hunt

http://www.serverscripting.com
http://www.wshscripting.com



Mon, 15 Dec 2003 05:30:03 GMT  
 Regular expression pattern



Quote:
> root says:

> >I have fiddled and twiddled, and got it to work with : <drum roll>
> >Pattern =

>"\w+\=\""[(\w|\.|\-|\&|\#|\;|\:|\/)+\s*]*\s*\""|\w+\=\'[(\w|\.|\-|\&|\#|\;|
\
> >:|\/)+\s*]*\s*\'"

> >could anyone optimize it?

> How about this...

> Pattern = "([^=]+)=['""](.+)['""]"

Thanks, but it doesn't do the job. The reason is, that I am processing an
HTML/XML hybrid document from a data provider. The data provider is
returning this hybrid document with inconsistent standards.
Sometimes, XML element attributes are contained within double quote
delimiters, some XML element attributes are contained within single quotes,
and some XML elements have attributes with both single and double quote
deleimiters in the same tag! It's catering for all these possibilities that
has been the headache, but thankyou for your input.

root

- Show quoted text -

Quote:

> ----------
> Randy Hunt

> http://www.serverscripting.com
> http://www.wshscripting.com



Mon, 15 Dec 2003 15:56:47 GMT  
 Regular expression pattern


Quote:



>> root says:

>> >I have fiddled and twiddled, and got it to work with : <drum roll>
>> >Pattern =

>>"\w+\=\""[(\w|\.|\-|\&|\#|\;|\:|\/)+\s*]*\s*\""|\w+\=\'[(\w|\.|\-|\&|\#|\;|
>\
>> >:|\/)+\s*]*\s*\'"

>> >could anyone optimize it?

>> How about this...

>> Pattern = "([^=]+)=['""](.+)['""]"

>Thanks, but it doesn't do the job. The reason is, that I am processing an
>HTML/XML hybrid document from a data provider. The data provider is
>returning this hybrid document with inconsistent standards.
>Sometimes, XML element attributes are contained within double quote
>delimiters, some XML element attributes are contained within single quotes,
>and some XML elements have attributes with both single and double quote
>deleimiters in the same tag! It's catering for all these possibilities that
>has been the headache, but thankyou for your input.

I've still to get to grips with regular expressions in vbscript, but
here's one that works in Perl and seems to do what you ask. The value
is returned in the variable associated with the second set of
parentheses (Perl calls it $2):

        \w\s?=\s?(['"])(.+)(\1)

Translation to vb presumably requires doubling or escaping the " in
the [].

--
With best wishes
John

Please reply to the newsgroup and not by e-mail.



Tue, 16 Dec 2003 04:01:03 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Regular Expression Pattern Problem

2. needed: regular expression pattern

3. needed: regular expression pattern...

4. regular expression pattern

5. Regular Expression Pattern with Smart Quotes

6. HELP - adv. regular expression - pattern

7. This regular expression pattern should be easy

8. Regular Expression -Pattern Operator

9. regular expression pattern for URL

10. : Regular Expression -Pattern Operator

11. Regular expressions and/or pattern matching in VBA?

12. Regular Expressions to Match a Pattern

 

 
Powered by phpBB® Forum Software