All Questions
Tagged with regex preg-replace
3,262
questions
0
votes
0
answers
45
views
Do I need preg_replace_callback() to replace all matches in a text? [duplicate]
As part of a migration, I wrote a function to transform links, prepending a path ("/my/files") to existing paths from the source site. Here is my function:
function example_file_urls($text) ...
0
votes
2
answers
66
views
PHP perl regular expression - URL not preceded by equal sign and possible single or double quote
I'm trying to create a perl regular expression that matches a URL that is not preceded by an equal sign and one single or double quote (optional) ignoring whitespace. The code below gives an error: ...
-1
votes
1
answer
93
views
Replacing quotes with single quotes between two strings in php using preg_replace [duplicate]
I'm looking for a preg_replace that can replace " with ' when between font-family: and ;
I'm having an issue with my some dynamic html I'm using which requires me to replace the quotes with ...
0
votes
0
answers
43
views
REGEX search only affecting last occurence in preg_replace function in PHP error [duplicate]
I have a function highlighting word for a glossary. I created a regex to replace occurrence of word that are preceded and followed by word starting/ending characters like spaces, commas, HTML tags, ...
0
votes
2
answers
69
views
Replace portion of url filepath found in HTML page text
Given some urls inside an html page, I want to replace some urls as below:
Example url: https://example.com/cost-center/sub-one/article1
From that one I want to replace the text that is between /cost-...
0
votes
2
answers
69
views
Convert html headlines to list elements in PHP
I am learning php language.
I want to show the table of contents for the article. Convert the headings (h2,h3,h4,...) into a list and create links.
This is my php code.
$Post = '
<h2>Title 01<...
0
votes
1
answer
44
views
With PHP/Preg, how is it possible to replace a string not followed by any character [duplicate]
For example, I have two strings
"abcdef"
"abcdefghijk"
I want to replace the first one, but not the second one which begins with the same string. However, the first one can be ...
0
votes
2
answers
80
views
Add newlines to separate text and only hashtags that appear at the end of the string
I've already tried a couple of regex but cannot fix this one:
I need an enter line before the hashtags start (so there is some space).
Example:
It's essential to keep your pup cool in the summer ...
1
vote
2
answers
43
views
Weird PHP preg_replace result
$pedit =<<<head
<div class="item"><div var="i_name_10">white gold</div> <div var="i_price_10">$5.99</div></div>
head;
$...
1
vote
1
answer
53
views
Regex (php) to match single [ or single ] but ignore anything between [[ ]]?
I have a string, and within it there will be combinations of [ ] [[ ]] ][ but I need to replace the single [ and ] with < and > but leave alone (don't match) anything that is between [[ ]].
I ...
1
vote
1
answer
57
views
Convert Apple Maps coordinates in universal format
I would like to convert the coordinates displayed in Apple Maps as
38,89016° N, 1,22427° O
(German notation)
or
38.89016° N, 1.22427° E
(English notation)
into something like
38.89016, 1.22427
(...
1
vote
1
answer
66
views
preg_replace_callback of url in textarea cuts off at underscore or colon
Not sure how to proceed to allow or prevent snipping at underscore and colon in urls in this preg_replace. Also not sure what other special characters I might be missing that will snip the url
$text = ...
0
votes
1
answer
59
views
preg_replace reuse matched value in replacement value
I want to perform value replacement based on matched value. The replacement expression has calculation based on matched value.
regex
<?php
$re = '/<w:d([^\[]+)\/>/m';
$str = '<w:d2/>';...
-2
votes
2
answers
131
views
PHP Regex Get Text Between and inside tags
I have this tag on an HTML code:
text html [button link="google.com" color="#fff" text="this text here"] rest of html
I wish i could have the parameters of this "...
2
votes
2
answers
90
views
How to exclude image extension from string place in PHP
I want to replace all the string values from example.com to sample.com excluding the image extension .png, .jpeg, .jpg etc.
$body = ' www.example.com, example.com, example.com/hello.html, example.com/...