Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Regular Expression for content between two phrases (tags)?

    I want to use a regular expression that will find all content between a defined start and end phrase such as between </title> and </head> or between <!-- and --> for comments.

    Any combination of spaces, new lines, returns and any symbols, numbers and letters could occur between the defined start and end phrases that i mentioned above. So I only want the find to stop if it encounters that phrase in its entirety. I want the start and end phrase included in the replace operation.. So i can alter them too if necessary.

    This is for use in Dreamweaver's Find and Replace. Thanks

  • #2
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    How is this a Javascript question?

    Anyway, try this

    Code:
    <STARTTAG>(.*?)<ENDTAG>
    Keep in mind that you may have to escape your surrounding tags to not be mistaken for regular expressions. The above expression typically does a non-greedy match on any text in between the two tags. It has to be non-greedy or it would search the first start tag and the last end tag and match everything in between, even other occurences of the tags.

    Since I'm not familiar with Dreamweaver, I don't know if its F&R will select the tags, too. But it works the intended way in Eclipse.
    Last edited by Airblader; 03-02-2013 at 09:35 PM.

  • #3
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks... The only thing is it isn't working with new lines in Dreamweaver.. It did work on a regex tester i used with new lines though.

    I just needed to escape the \< and \>

    Any advice on including new lines too? I'm not sure what type of RegEx Dreamweaver uses but it does seem to respond to \n

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,277
    Thanks
    10
    Thanked 581 Times in 562 Posts
    there is a snag in js's copy of the perl regexp engine (like used in dreamweaver's webkit core), so the dot symbol only hits one kind of rep at once; to wit, switching between whitespace lines and wordy boundries fools it.

    the workaround is to use a brace to specify anything:

    Code:
    /<STARTTAG>([\w\W]*?)<ENDTAG>/gi
    Last edited by rnd me; 03-03-2013 at 12:24 AM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •