Useful Regex Expressions

In this page, we list useful regex expressions. You could use regex expressions on find and replace methods.

Getting First Paragraph

For post content, plugin automatically gets all paragraphs. If you want to get only first paragraph, you could modify post_content’s xpath expression like this :

//div[contains(@class, “description”)]/p

Simply adding [1] at the end, will provide us only first paragraph.

//div[contains(@class, “description”)]/p[1]

Reordering any data

(.*?) means everything on regex. If you have a time format like 01-12-1995, you could capture it like this : (.*?)-(.*?)-(.*?) . On find section, you should write that to capture all time format. On replace section, you could reorder this information. For example, $2-$1-$3 will return you 12-01-1995. 1, 2 and 3 means their order.

Cleaning empty lines

With this regex expression, you could remove any empty line from your content. Leave replace field empty and paste to find field this :

^[ \t]*$\r?\n

Trim or remove empty spaces

With this expressions, you could trim your content on the left and right side. Leave replace field empty and paste to find field this :

^[ \t]+

Get Last Word From String

You could get last word from string with find&replace expressions.

Find : (.*)\s(.\w*)
Replace : $2

Was This Article Helpful?

Related Articles

There are no comments yet

Leave a comment

Your email address will not be published.