Page 1 of 1

String replacing with Regex

Posted: Wed Dec 18, 2013 1:03 pm
by MaxV
Hello,
I read on forum and search engines, but I didn't find a solution.
I need to substitute in a text like this:

Code: Select all

# Title 1
Some text, very long...
# Title 2
Some other text, very long...
...
to html like this:

Code: Select all

<h1># Title 1</h1>
Some text, very long...
<h1>#Title 2</h1>
Some other text, very long...
...
I can't use replace, since I have to store the content between # and newline.
I can't use neither matchText(), because I don't know how many replace I need.
I only know that a good regex for my seach is:

Code: Select all

(\n|^)#.*\n
Do you have any idea?

Re: String replacing with Regex

Posted: Wed Dec 18, 2013 1:54 pm
by Klaus
Hi Max,

I have no idea about RegEx, so I would do something like ntis:

Code: Select all

...
## tRawText will contain your list WITHOUT htmltags
## tHTMLText = your list with htmltags
put empty into tHTMLText
repeat for each line tLine in tRawText
  if char 1 of tLine = "#" then
    put "<h1>" & tLine & "</h1>" & CR after tHTMLText
  else
   ## You might want to add <p></p> tags here ;-)
   put tLine & CR after tHTMLText
 end if
end repeat
delete char -1 of tHTMLList
## Now do whatever you like with tHTMText
...
:D


Best

Klaus

Re: String replacing with Regex

Posted: Wed Dec 18, 2013 3:08 pm
by MaxV
Thank you Klaus, I'll try to do all my tasks with chunk expressions...

Re: String replacing with Regex

Posted: Wed Dec 18, 2013 3:33 pm
by Klaus
Oops, little typo in the last 2 lines:
...
delete char -1 of tHTMLText ## not tHTMLList!
## Now do whatever you like with tHTMLText
...

Re: String replacing with Regex

Posted: Thu Dec 19, 2013 5:00 pm
by MaxV