Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-11-2013, 08:14 AM
tinfanide tinfanide is offline Regular Expressions: match words within quotes? Windows 7 64bit Regular Expressions: match words within quotes? Office 2010 32bit
Expert
Regular Expressions: match words within quotes?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default Regular Expressions: match words within quotes?

I want to match
Quote:
images/folder 1/pic 009.JPG
in the following text:


Quote:
<gallery>
<pic path="images/folder 1/pic 009.JPG" desc="desc 1" />
<pic path="images/folder 1/pic 010.JPG" desc="desc 2" />
</gallery>
but it just matches the part (stated in the comments below in the codes)
Code:
Sub RegExp()

Dim oRegExp As RegExp
Dim oMatchCollection As MatchCollection
Dim oMatch As Match

Set oRegExp = New RegExp

''
oRegExp.Pattern = """.*JPG"""
'' return:
'' "images/folder 1/pic 009.JPG" desc="desc 1" /><pic path="images/folder 1/pic 010.JPG"

oRegExp.Global = True
oRegExp.IgnoreCase = True
'' oRegExp.MultiLine = False

Set oMatchCollection = oRegExp.Execute(ActiveDocument.Range)

For Each oMatch In oMatchCollection
    Debug.Print oMatch.Value
Next oMatch

Set oMatch = Nothing
Set oMatchCollection = Nothing
Set oRegExp = Nothing
End Sub
Reply With Quote
  #2  
Old 01-29-2013, 08:43 PM
macropod's Avatar
macropod macropod is offline Regular Expressions: match words within quotes? Windows 7 64bit Regular Expressions: match words within quotes? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If this is for Word, why not use its wildcard facilities?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-02-2013, 08:21 AM
tinfanide tinfanide is offline Regular Expressions: match words within quotes? Windows 7 64bit Regular Expressions: match words within quotes? Office 2010 32bit
Expert
Regular Expressions: match words within quotes?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
If this is for Word, why not use its wildcard facilities?
Can you give a hint, please?
Reply With Quote
  #4  
Old 02-02-2013, 10:07 PM
macropod's Avatar
macropod macropod is offline Regular Expressions: match words within quotes? Windows 7 64bit Regular Expressions: match words within quotes? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Since I don't know what you want to do with the found text, this is fairly generic:
Code:
With ActiveDocument.Content
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = """images/folder 1/pic [0-9]{3}.JPG"""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    MsgBox .Text
    .Find.Execute
  Loop
End With
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expressions: match words within quotes? Changing single-quotes to double-quotes Bobosmite Word 5 04-15-2013 06:40 AM
Regular Expressions: match words within quotes? Regular expressions: lower case after hyphen SusanG Word 2 06-06-2012 11:58 PM
Regular Expressions: match words within quotes? Regular Expressions: [!0-9] does not work??? tinfanide Excel Programming 4 05-30-2012 04:09 AM
Exporting without Quotes Chris1 Excel 6 02-16-2012 11:20 PM
Issue skipping characters by Regular Expressions in Word pochtara Word VBA 0 04-01-2010 05:37 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft