RegEx: can't figure this out!

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default RegEx: can't figure this out!

    Hello everyone, I have been trying for days to get this right but I can't seem
    to grasp it: I'm trying (ofcourse) to match a substring inside a string, but
    want to skip other occurrences of the same substring. I'll give an example to
    stay comprehensible: My string: Some text<font color='red'>I'm building a new
    front here where the frontier used to be</font> some more text. I'm trying to
    match 'ont', but only the occurrences outside the tags, ie, it has to skip the
    'ont' in '<font color=...>' and '</font>', but it has to come up with the 'ont'
    in 'front' and 'frontier'. I found RegEx that strip the tags, but I want to
    keep them, just not show up in the results. I want to skip the tags, not remove
    them. I would be very grateful to those who can help help me, thanks in
    advance. Laurens Bloem

    Laurens Guest

  2. Similar Questions and Discussions

    1. Trying to figure out CF and IIS
      Hello, I just found out about the free CF Developer, so I wanted to download, install, and see if I could learn it. I'm not sure what I've done...
    2. Help me figure out how I did this!!!
      Ok, so without being able to show anyone, what I have is a highly pixelated black and white head shot of myself. Mosaic, except w/ no grout and all...
    3. See if you can figure this one out....
      I have a simple ASPX page being hosted on our ISP. The page contains 2 textboxes, and one button: http://www.jonkar.ca/nora/xtest.aspx You put...
    4. Trying to figure this out
      Just trying to figure this out but can't. Can someone help with this effect? ...
    5. Need to figure this one out
      Hey all Looks like I'm officially the art guy in the band now.....SO I've been asked to design something with this concept: ...
  3. #2

    Default Re: RegEx: can't figure this out!

    Anyone? Pretty please?
    Laurens Guest

  4. #3

    Default Re: RegEx: can't figure this out!

    > Some text<font color='red'>I'm building a new
    > front here where the frontier used to be</font> some more text.
    This is tricky, because - as near as I can tell - you can't tell a regex to
    NOT match a specific character sequence. You can tell it to match a
    something that isn't a character (or a set of characters), but not a set
    sequence.

    You could easily enough get it to match [^f]ont, but that would also skip
    the word "font" (and anything else with that sequence in it) within the
    text, too.

    I'd probably swap out <[/]?font matches for something else, then deal with
    your "ont" issue, then swap the font tags back in again. Pity to do it in
    three steps, but I can't think of another way of doing it.

    --

    Adam
    Adam Cameron Guest

  5. #4

    Default Re: RegEx: can't figure this out!

    Hi Adam, thanks a lot for your reply.I thought of that, but then I'm left with
    the problem that it still finds <TD class='content'> for example, and I need to
    skeep all tags... Do you think I can find every ont in tags, so between < and
    >. If I can REreplace those by some strange string, than your solution will
    work, using one step to change every 'ont' that's inbetween < and > to
    something like '___temporarily_changed___', then a second step that simply
    replaces every ont still in the string, then a third to change back all the
    '___temporarily_changed___' to 'ont'. Thanks for your help, I'll try to find
    how to find 'ont's within tags. If that's easy to you, please answer back.
    Kind regards, Laurens

    Laurens Guest

  6. #5

    Default Re: RegEx: can't figure this out!

    >Do you think I can find every ont in tags, so between < and
    >>. If I can REreplace those by some strange string, than your solution will
    > work, using one step to change every 'ont' that's inbetween < and > to
    > something like '___temporarily_changed___', then a second step that simply
    (<[^>]*)(ont)([^>]*>)

    Seems to work. Only tested it for about 30sec, though.

    All this begs the question... WHY are you wanting to change all instances
    of ONT to something else? ;-)

    --

    Adam
    Adam Cameron Guest

  7. #6

    Default Re: RegEx: can't figure this out!

    Hi Adam, I took 'ont' as an example to stay comprehensible. What I'm doing is
    writing a HighLight UDF that looks for a search phrase (entered by the user)
    and highlights it in the found text. To highlight the occurrences of the search
    phrase in the found text, I replace the match with <span class='highlight'>the
    match</span>. But that is highly undesirable if the text contains tags, because
    they suddenly show up where they shouldn't looking highlighted. You could get
    something like <f<span class='highlight'>ont</span> color='red'>This is the
    fr<span class='highlight'>ont</span></f<span class='highlight'>ont</span> But
    if I explained that, and then asked my question, I would have lost everybody
    long before they got to the question ;-) Have a good weekend!! Laurens

    Laurens Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139