Re: Grep question [parsing variables] problem

This WebDNA talk-list message is from

2003


It keeps the original formatting.
numero = 47292
interpreted = N
texte = However there is a solution that replaces it in one run, regardless of the tags matching:[text]set_main_txt=[grep search=\[(\/?[bBiI])\]&replace=<\1>][text_main][/grep][/text]GyuriJohn Peacock wrote:> Palle Bo Nielsen wrote: > >> Hi John, >> >> Well it should have stated... >> >> this is a test [b]with bold [i]and bold italic[/i] words[/b] >> >> My bad when I wrote the mail to the list... but it still don't work... > > > Nor should it. You will have to replace the nested context first, or > else it will not work. In general, you will be unable to use grep to > manage nested search and replace; you really need to use a finite > state machine to do this in a consistent way. Here's why: > >> >> [!] -- REPLACE [b] WITH (ignore case) text [/!] >> [text]set_main_txt=[grep >> search=\[[bB]\]([^[unurl]%5B[/unurl]]*)\[/[bB]\]&replace=\1> b>][text]set_main_txt[/text][/grep][/text] > > > This part of the regex: > > \[[bB]\]([^[unurl]%5B[/unurl]]*) > > matches this part of the original text: > > [b]with bold [ > > but since there isn't an immediately trailing [/b], the search fails > and hence the replace never happens. > > You will have to do 4 searchs: 1 for each leading and trailing tag: > > [text]set_main_txt=[grep > search=\[[bB]\]&replace=[text]set_main_txt[/text][/grep][/text] > [text]set_main_txt=[grep > search=\[/[bB]\]&replace=[text]set_main_txt[/text][/grep][/text] > > [text]set_main_txt=[grep > search=\[[iI]\]&replace=[text]set_main_txt[/text][/grep][/text] > [text]set_main_txt=[grep > search=\[/[iI]\]&replace=[text]set_main_txt[/text][/grep][/text] > > However, this would still not _disply_ correctly if, as you originally > posted, one of the closing tags was missing (the rest of the page > would be boldface). > > HTH > > John >-- Gyuri Ordody Objects Online, Inc.------------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list . To unsubscribe, E-mail to: To switch to the DIGEST mode, E-mail to Web Archive of this list is at: http://webdna.smithmicro.com/ Associated Messages, from the most recent to the oldest:

    
  1. Re: Grep question [parsing variables] problem (Gyuri 2003)
  2. Re: Grep question [parsing variables] problem (Rob Marquardt 2003)
  3. Re: Grep question [parsing variables] problem (Gyuri 2003)
  4. Re: Grep question [parsing variables] problem (John Peacock 2003)
  5. Re: Grep question [parsing variables] problem (Palle Bo Nielsen 2003)
  6. Re: Grep question [parsing variables] problem (John Peacock 2003)
  7. Grep question [parsing variables] problem (Palle Bo Nielsen 2003)
However there is a solution that replaces it in one run, regardless of the tags matching:[text]set_main_txt=[grep search=\[(\/?[bBiI])\]&replace=<\1>][text_main][/grep][/text]GyuriJohn Peacock wrote:> Palle Bo Nielsen wrote: > >> Hi John, >> >> Well it should have stated... >> >> this is a test [b]with bold [i]and bold italic[/i] words[/b] >> >> My bad when I wrote the mail to the list... but it still don't work... > > > Nor should it. You will have to replace the nested context first, or > else it will not work. In general, you will be unable to use grep to > manage nested search and replace; you really need to use a finite > state machine to do this in a consistent way. Here's why: > >> >> [!] -- REPLACE [b] WITH (ignore case) text [/!] >> [text]set_main_txt=[grep >> search=\[[bB]\]([^[unurl]%5B[/unurl]]*)\[/[bB]\]&replace=\1> b>][text]set_main_txt[/text][/grep][/text] > > > This part of the regex: > > \[[bB]\]([^[unurl]%5B[/unurl]]*) > > matches this part of the original text: > > [b]with bold [ > > but since there isn't an immediately trailing [/b], the search fails > and hence the replace never happens. > > You will have to do 4 searchs: 1 for each leading and trailing tag: > > [text]set_main_txt=[grep > search=\[[bB]\]&replace=[text]set_main_txt[/text][/grep][/text] > [text]set_main_txt=[grep > search=\[/[bB]\]&replace=[text]set_main_txt[/text][/grep][/text] > > [text]set_main_txt=[grep > search=\[[iI]\]&replace=[text]set_main_txt[/text][/grep][/text] > [text]set_main_txt=[grep > search=\[/[iI]\]&replace=[text]set_main_txt[/text][/grep][/text] > > However, this would still not _disply_ correctly if, as you originally > posted, one of the closing tags was missing (the rest of the page > would be boldface). > > HTH > > John >-- Gyuri Ordody Objects Online, Inc.------------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list . To unsubscribe, E-mail to: To switch to the DIGEST mode, E-mail to Web Archive of this list is at: http://webdna.smithmicro.com/ Gyuri

DOWNLOAD WEBDNA NOW!

Top Articles:

Talk List

The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...

Related Readings:

authorizenet/webmerchant (2000) Passing Cart variable to subdirectory files? (1997) Updating a database once per day - An example (1998) WebCat2b13MacPlugIn - syntax to convert date (1997) WebSTAR 2.1 freezes my Mac (1997) Keep away (1997) BUG: Switch inside ListFields context (2005) Problem with broken images (2004) Mac Vs WindowsNT (1997) I've been framed by webcatalog! Does anyone know the way out? (2000) WebCatalog 4.0.2b5 available (2000) Extra carriage returns (1999) WebDelivery: One step closer !! (1997) Off Topic: MacOS X Server on iMac (2000) [OT] Weird returned mail - whaddya think? (2002) japanese characters (1997) Template Encrypt Speed (1998) [WebDNA] Protect help... Beginner Question (2008) problems with 2 tags (1997) Re:Version 2.0 and 1.6 simultaneous (1997)