Help with regex (find replace html tags)

Hello

I am trying to find a string and replace it with another one, but i am facing issue when the string has line breaks/spaces in it

I am trying to find the following

<tbody>
	<tr>
		<td>
			{{ username }}
		</td>
	</tr>
	</tbody>

and replace it with the following:

	<thead>
	<tr>
		<td>
			{{ salutation }}
		</td>
	</tr>
	</thead>
	<tbody>
	<tr>
		<td>
			{{ username}}
		</td>
	</tr>
	</tbody>

This is my regex which apparently isnt working the way I expect it to work

<\s*tbody[^>]*>(.*?)<\s*/\s*tbody>

Can someone please help me with this?

Many thanks

try simplexml with simplexml_load_string on DOM related data.

Looks like you need PCRE_MULTILINE modifier.

Though I really hope it’s one-time task, not some part of the template logic.

too lazy to double answer: http://www.codingforums.com/php/379136-help-regex-find-replace-html-tags.html

1 Like

Hey Guys

Thanks for the reply.

I found a solution. The following regex worked fine for me

/\s*<tbody><tr>\s*<td>\s*{{ username }}\s*<\/td>\s*<\/tr></tbody>/

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.