I am sending a few telnet cmds to a device and reading back its result values in a array. I need to filter the data, but I’m not sure if preg_split() or preg_match() is better suited. After isolating the desired rows of text, I need to store several portions of text in a mysql table — for each row. All
Tag: regex
str_contains returns true, but preg_match returns false
I am getting the HTML code of this website – https://theatrevazrajdane.bg/%D1%82%D0%B2%D0%BE%D1%80%D1%87%D0%B5%D1%81%D0%BA%D0%B8-%D1%81%D1%8A%D1%81%D1%82%D0%B0%D0%B2/%D0%B0%D0%BA%D1%82%D1%8C%D0%BE%D1%80%D0%B8/2 with this code $html = file_get_contents($url) and then I am running a simple regex which does not work and I have no idea why. This code output – FALSE and this code output – TRUE Do you know where it could be the reason I checked the HTML several
Finding all 1 digit and 2 digits numbers in a larger number using regex
I want to match all 1 digit and 2 digit numbers using regex. Subject string: ‘12345’ Expected match: 1,2,3,4,5,12,23,34,45 I’m trying: d(d)? but as result i get 12,2,34,3,5 Answer You can use See the PHP demo. Output: NOTES: (?=((d)d?)) – a regex that captures into Group 1 two or one digits, and into Group 2 the first digit of the
Regex to match a result that isn’t single line and expanded across multiple lines
I want to change /<?phps([sS]*?)?>/gi the way that single line PHP tags become excluded. For example, here I want to match only second PHP tag and not the first one: Answer You can use A variation with multiline .: See the regex demo. Details: <?php – a <?php substring (?!S) – a right-hand whitespace boundary (immediately to the right, there
How get first two only word from string and replace whitespace by underscore (_)
here is the case, I had a string variable contains a fullname with title. I wanna get the name only, without the coma and the title. Then I replace the white space result with underscore (_). what I’ve tried : How to get the result like : john_doe from the variable $name ? Answer You could use preg_replace to first
PHP: Split a string at the first period that isn’t the decimal point in a price or the last character of the string
I want to split a string as per the parameters laid out in the title. I’ve tried a few different things including using preg_match with not much success so far and I feel like there may be a simpler solution that I haven’t clocked on to. I have a regex that matches the “price” mentioned in the title (see below).
This regex works on regex101 but not in my script, why?
I have this regex: Which is not working as it should, see this code: I wrote my regex using this and it is working fine, until i add the regex to my script. https://regex101.com/r/EmebOT/1 If i replace [aàâ] with “â” in the regex so the regex looks like this, it works: Answer I got this working with use of the
Regex to find repeated sentences from more to less
i have string like $string = “hello this is a string and hello but this is a string hello but this is a string and “; in it there is repeated words and repeated sentences but i only want the sentences so i expect hello but this is a string to be captured i tried using this regex (.{10,}).*?1 but
How to pass the parameters properly for a callback function for preg_replace_callback using a preexisting function?
I am getting this error: Parse error: syntax error, unexpected ” (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)……… eval()’d code on line 2 Since removing e from the regex expression ~<IF (.?)(?<!-)>(.?)~se as shown in the line below because it became deprecated. I understood I need to use preg_replace_callback() and rewrite using an anonymous function however I
How would I match all “quote blocks” in plaintext e-mail in PHP PCRE?
I’m trying to match all the quotes in the following example e-mail message: That means I want to match these three strings: And: And: I don’t understand how I can do this, since if I use the s flag to span multiple lines, which is required for this, I cannot refer to ^ and $ to mean “beginning of line”