Pregunta

I'm working with a Filemaker Pro database. Which for some reason won't export XML that is written into the database. It entitizes all the special characters making it difficult to export the embedded XML into an actual XML document. To combat this I have decided to use a regular expression in a find and replace to target asterisks that I'm putting on both sides of a word or phrase.

Example:

**Word to put tags around*

I have a regular expression that matches two asterisks that are adjacent. But I cant remember how to match a single asterisks that IS NOT adjacent to another. Once I can target one and then the other separately I will find and replace them with the appropriate tag.

¿Fue útil?

Solución

If it supports negative lookarounds, you can use just that:

(?<!\*)\*(?!\*)

That will match single asterisks only.

(?<!\*) prevents matches if preceded by an asterisk.

(?!\*) prevents matches if followed by an asterisk.

Otros consejos

Another option would be to match the * and the surrounding non-*.

([^*]|^)[*]([^*]|$)

Regular expression visualization

You could use this for example to replace single * to ** like this

s.replace("([^*]|^)[*]([^*]|$)","$1**$2");
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top