Jump to content

Remove WYSIWYG &nbsp with regex


Hybride

Recommended Posts

I have a WYSIWYG editor that converts the text to HTML format after submitting.

 

I have text that looks like this:

Test with:

^blah blah/XLR

^Another test/?                     

Synonyms 

Some Syndrome 

^ED test syndrome

Synonyms/acronyms

Test

^Another

 

Which would get converted to something ugly like this:

<p>
                              Test with:<br />
                                    ^blah blah/XLR                                    <br />
                                    ^Another test/?                      <br />
                                        Synonyms   <br />
                                            Some Syndrome  <br />
                                    ^ED test syndrome<br />
                                        Synonyms/acronyms<br />
                                            Test<br />
                                            ^Another</p>

 

Doing this regex

\^(.*)

Gets me the ^words that I need, but also gets me the &nbsps that I don't on the right hand side. How can I modify the regex to only get before and not including the   ?

Link to comment
Share on other sites

There are several solutions.

 

1. Use str_replace() to remove the   after extracting the line you need

Does every line with '^' have an ' ' at the end? If so,

2. If you don't expect the ampersand to be included in the data you can change the regex to \^([^&]*)\

3. If the ampersand can be in the data you need then you can use this regex \^([.*) \ - may need to escape some of those characters

Link to comment
Share on other sites

Thanks, Psycho! I actually changed my regex to this:

\^(.*)(|( ))

And for now, looks like it's working.

 

The '^' is at the beginning of each line that I need to do the regex on, but &nbsp may or may not be there (could be just a line break). Realizing this, I modded to include two '^' in case anyone used it within a paragraph (such as '^test this^'). The regex for that is

((\^(.*)\^))|\^(.*)(|( ))|

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.