Skip to content
Advertisement

Tag: regex

PHP change file extension in HTML as plaintext

I want to change file extension in HTML code on PHP output. Probably with regex and this is something I really cannot handle.. …some code…<img data-src=’https://static.example.com/gallery/image.jpg’>…some code… should be changed to …some code…<img data-src=’https://static.example.com/gallery/image.webp’>…some code… Please note that: there might be any number of occurances (zero, one, multiple), I want to change only those from https://static.example.com/gallery/ and not from https://example.com

JS Regex named groups with replace()

In JS, I’m trying to build an object from the below code. However I’m stuck at getting regex named groups with the below replace function. NOTE: What I’m trying to do is, Select characters from str variable from “:” to “,” and replace it with formatters values. Then make the string an object. Answer Regex Demo

Can’t figure out a solution to this regex

I have the following list of strings: and the following regular expression which should run on all strings, and if a match is found, return true otherwise, return false. /(?<!hdds)(dtb hdd dtb){1,}(?!shdd)/ As of now, my result set looks something like this: However, for the correct result, would be, to mark c4 as true instead. How could I change my

Replace all non printable characters except newline characters

I want to replace all non printable characters, especially emojis from a text but want to retain the newline characters like n and r I currently have this for escaping the non printable characters but it escapes n and r also: Answer [:print:] is a POSIX character class for printable chars. If you use it in a negated character class,

PHP preg_split, split at | and check for minimum 3 chars

I want to separate at the “|” and check the length to at least 3 characters Can anybody help me? https://www.phpliveregex.com/p/AdQ Answer I think doing this in a regex might not be the best tool for the job, but if you want to use it here might be a possibility: https://regex101.com/r/Pz3YCH/1 Again though, I think doing a string split would

Using PHP preg_replace() with a string variable, where the variable needs to represent multiple permutations of itself

Using: I’d like to replace, case-insensitively, the text contained in $My_String, which I can achieve with: If $My_String is alpha beta gamma delta, this will identify: alPhA beTa GammA DeLta aLpHa bEta gAMma delTa etc. So far, so good. But any spaces and hyphens in $My_String must also be regarded as equivalent. So the preg_replace() function also needs to identify

PHP RegEx preg_match_all Reiterate Matched Words Before the Current Match

I have the following RegEx code I expect the matches to include: word1 word2 word3 keyword word4 word5 word6 word4 word5 word6 keyword word7 word8 word9 But in reality, I’m getting these: word1 word2 word3 keyword word4 word5 word6 keyword word7 word8 word9 In other words, the second match is cropped because of the 1st match. Here’s a test: https://regex101.com/r/EPp14b/1/

RegEx (preg_match_all in PHP) to capture series of up to the first alphanumeric character

The problem here is the conflict between numbers and alphanumeric in the problem description. Given the text: <0><1><2><3><4><5><6><7><8><9><10><11><12><13><14><15><16><17><18>The next 11 keys can change the SWING from OFF (50%) to <19><20><21><22><23><24><25>80<26><27><28><29><30><31><32>% during arpeggiator or sequencer operation.<33><34> I need to extract the following four groups: Reason: we want to display this in a much more user-friendly way as… [1]The next 11 keys

Weird PHP Regex Preg_Match Bug?

My PHP version is PHP 7.2.24-0ubuntu0.18.04.7 (cli). However it looks like this problem occurs with all versions I’ve tested. I’ve encountered a very weird bug when using preg_match. Anyone know a fix? The first section of code here works, the second one doesn’t. But the regex itself is valid. For some reason the something_happened word is causing it to fail.

PHP reg expression to detect variable in string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year. Improve this question I could never figure out reg expressions, no matter how hard I tried. Need some help pretty please: I want to

Advertisement