preg-match

Find the occurrence of backslash in a string

旧巷老猫 提交于 2019-12-02 03:11:09
If my string is : aud\ios , how do i check it out for the presence of \ in it? I tried using preg_match('\\' , $string) but it does not work. What's the correct way to achieve this? Amal Murali For something simple as this, you don't need a regular expression. A string function like strpos() should be enough: if (strpos('aud\ios', '\\') !== FALSE) { // String contains '\' } Note that you need to escape the backslash here. If you simply write \ , then PHP considers it as an escape sequence and tries to escape the character that follows. To avoid this, you need to escape the escape using another

How to extract only part of string in PHP?

旧时模样 提交于 2019-12-02 03:10:17
I have a following string and I want to extract image123.jpg. ..here_can_be_any_length "and_here_any_length/image123.jpg" and_here_also_any_length image123 can be any length (newimage123456 etc) and with extension of jpg, jpeg, gif or png. I assume I need to use preg_match , but I am not really sure and like to know how to code it or if there are any other ways or function I can use. You can use: if(preg_match('#".*?\/(.*?)"#',$str,$matches)) { $filename = $matches[1]; } Alternatively you can extract the entire path between the double quotes using preg_match and then extract the filename from

need a regex to parse a csv file with double quotes in php

不羁岁月 提交于 2019-12-02 02:51:52
问题 Trying to parse a csv file that has all the data wrapped in double quotes, because there may be commas in the double quotes. Looks like this: $songs = '"1, 2, 3, 4 (I Love You)","Plain White T's","CBE10-22",15,"CBE10-22","","","CB",984,"","10/05/10"'; $regResult = preg_match( "", $songs, $matches ); I can't figure out a regex that will return the data between the quotes as the matches. I'm sure there is some regex master that can help me with this. 回答1: you dont need no stinkin regex to parse

Warning: preg_match() [function.preg-match]: Unknown modifier [duplicate]

血红的双手。 提交于 2019-12-02 02:27:13
This question already has an answer here: Warning: preg_replace(): Unknown modifier ']' 3 answers I'm getting this error... Warning: preg_match() [function.preg-match]: Unknown modifier '1' in C:\path-to-plugin.php on line 147 When I run the keyword "Test $2/1 test+word!" through the function below function my_get_kw_in_content($theKeyword, $theContent) { //ERROR OCCURS NEXT LINE return preg_match('/\b' . $theKeyword . '\b/i', $theContent); } I'm assuming that I need to sanitize the keyword to escape the "/" character (and possibly more). I'd appreciate any suggestions you have to sanitize the

How to remove content from url after question mark. preg_match or preg_replace?

为君一笑 提交于 2019-12-02 01:05:30
Im working on some function to grab few data from url with simple html dom. But one of the data is an image and image have question mark and some more info behind it. So example of url would be something like this. http://somesite.com/uploaded/images/8.jpg?m=eSuQKgaaaa&mh=t0i7nVhjZleTJ5Ih So this content behind question mark is some sort of the code that makes images resized to small size. If i would just take this http://somesite.com/uploaded/images/8.jpg Images would be in bigger resolution and that's what i need. I know there is a function like preg_match but i never understood expressions

regular expression with hebrew or english

99封情书 提交于 2019-12-02 00:58:09
I'm looking for a pattern that accept only hebrew or english letters from 2 letters to 15, and can accept 1 space. I have tried following code but it does not matching my string: <?php $subject = "שלום לך"; $regexp="#^\p[{Hebrew}| ][a-zA-Z]{2,15}? \+$#u"; print_r(preg_match($regexp, $subject)); ?> There are multiple errors in your code. First, your regex $regexp="#^\p[{Hebrew}| ][a-zA-Z]{2,15}? \+$#u"; Here is what it means: # : regex delimiter ^ : begining of string \p : character p [{Hebrew}| ] : character class, one of the char : {, H, e, b, r, w, }, |, space [a-zA-Z]{2,15}? : from 2 to 15

Regex for getting information from square brackets

人走茶凉 提交于 2019-12-01 23:00:21
I'm attempting to make something like shortcodes in WordPress, and I'm looking for a regex that will take something like [title:This is a title] and turn it to just This is a title . It would also be useful if someone could suggest a way to take something like [code:some code] and turn that into an array in the form of array( [0] => 'code' [1] => 'some code') or array( 'code' => 'some code' I've tried a few different regexes I've found here and there, but none of them seem to work. Thanks preg_replace('/\[.*?:(.*?)\]/', '$1', $str); CodePad . If you wanted to capture the text before the colon,

Matching for case insensitive exact phrase with spaces

◇◆丶佛笑我妖孽 提交于 2019-12-01 20:55:33
问题 If I have a string "Hello I went to the store today" and I had an array of matches $perfectMatches = array("i went","store today"); It should match both of those. (the array can get quite large so i'd prefer to do it in 1 preg_match) Edit: Got this one working! thanks! preg_match_all("/\b(" . implode($perfectMatches,"|") . ")\b/i", $string, $match1) I also need a separate regular expression that is kind of hard to explain. Say I have an array $array = array("birthday party","ice cream");/

Matching for case insensitive exact phrase with spaces

て烟熏妆下的殇ゞ 提交于 2019-12-01 20:11:06
If I have a string "Hello I went to the store today" and I had an array of matches $perfectMatches = array("i went","store today"); It should match both of those. (the array can get quite large so i'd prefer to do it in 1 preg_match) Edit: Got this one working! thanks! preg_match_all("/\b(" . implode($perfectMatches,"|") . ")\b/i", $string, $match1) I also need a separate regular expression that is kind of hard to explain. Say I have an array $array = array("birthday party","ice cream");//this can be very long Is it possible to get a regular expression that will match a string if "birthday"

How to match any word in a String with Regex in PHP

烈酒焚心 提交于 2019-12-01 20:07:45
I have these strings. I want a regular expression to match them and return true when I pass them to preg_match function. do you want to eat katak at my hometown? do you want to eat teloq at my hometown? do you want to eat tempeyek at my hometown? do you want to eat karipap at my hometown? How do I create a pattern in regex that will match the above pattern? Like this: do you want to eat * at my hometown? Asterik (*) means any word. Here is the regex pattern that I have so far: $text = "do you want to eat meatball at my hometown?"; $pattern = "/do you want to eat ([a-zA-Z0-9]) at my hometown?/i