Tase
Tase

Reputation: 35

Javascript Regular Expression String List

I have a text file that looks like this:

1)  bla bla bla 

 bla bla bl- 

a bla bla 

 2)  bla bla bl- 

a bla bla bl- 

  a bla bla 


3)  bla bla bl- 

a bla bla bl- 

a bla bla 

I want to take every list item and put it inside a

<p class="bla"></p> 

html tag. I also want to fuse the words that are broken up into syllables.

I only managed to get the begining of the list item

^[ ]+[0-9]+\)

and words that end with the minus sign

[a-zA-ZäöüßÄÖÜ]+\-

I wish to do this in JavaScript, but if it can be done in notepad++ too better still.

Thanks

Upvotes: 0

Views: 125

Answers (1)

Bergi
Bergi

Reputation: 665111

I want to take every list item and put it inside a html tag

I would have recommended a <li> tag :-) What you want is the string that begins with [0-9]+\), is preceded by linebreaks or the file begin and is followed by either linebreaks and the next point, or the file end. This regex should do that:

(^|\s*\n\s*)\d+\)([\s\S]+?)(?=\s*$|\s*\n\s*\d+\))

Now you can replace it with $1<p class="bla">$2</p>. You might want to exclude some of the whitespaces from the matching groups to remove them.


I want to fuse the words that are broken up into syllables.

For that, we can match a word end, followed by the minus sign and linebreaks:

\b-\s*\n\s*

Then replace that with the empty string.

Upvotes: 1

Related Questions