preg-match

Preg_match_all <a href

孤街浪徒 提交于 2019-12-17 10:09:10
问题 Hello i want to extract links <a href="/portal/clients/show/entityId/2121" > and i want a regex which givs me /portal/clients/show/entityId/2121 the number at last 2121 is in other links different any idea? 回答1: Regex for parsing links is something like this: '/<a\s+(?:[^"'>]+|"[^"]*"|'[^']*')*href=("[^"]+"|'[^']+'|[^<>\s]+)/i' Given how horrible that is, I would recommend using Simple HTML Dom for getting the links at least. You could then check links using some very basic regex on the link

How to search in an array with preg_match?

╄→гoц情女王★ 提交于 2019-12-17 04:56:12
问题 How do I search in an array with preg_match? Example: <?php if( preg_match( '/(my\n+string\n+)/i' , array( 'file' , 'my string => name', 'this') , $match) ) { //Excelent!! $items[] = $match[1]; } else { //Ups! not found! } ?> 回答1: In this post I'll provide you with three different methods of doing what you ask for. I actually recommend using the last snippet, since it's easiest to comprehend as well as being quite neat in code. How do I see what elements in an array that matches my regular

Regex: Specify “space or start of string” and “space or end of string”

孤街醉人 提交于 2019-12-17 03:32:13
问题 Imagine you are trying to pattern match "stackoverflow". You want the following: this is stackoverflow and it rocks [MATCH] stackoverflow is the best [MATCH] i love stackoverflow [MATCH] typostackoverflow rules [NO MATCH] i love stackoverflowtypo [NO MATCH] I know how to parse out stackoverflow if it has spaces on both sites using: /\s(stackoverflow)\s/ Same with if its at the start or end of a string: /^(stackoverflow)\s/ /\s(stackoverflow)$/ But how do you specify "space or end of string"

Regex: Specify “space or start of string” and “space or end of string”

六眼飞鱼酱① 提交于 2019-12-17 03:32:00
问题 Imagine you are trying to pattern match "stackoverflow". You want the following: this is stackoverflow and it rocks [MATCH] stackoverflow is the best [MATCH] i love stackoverflow [MATCH] typostackoverflow rules [NO MATCH] i love stackoverflowtypo [NO MATCH] I know how to parse out stackoverflow if it has spaces on both sites using: /\s(stackoverflow)\s/ Same with if its at the start or end of a string: /^(stackoverflow)\s/ /\s(stackoverflow)$/ But how do you specify "space or end of string"

Get youtube id for all url types

泄露秘密 提交于 2019-12-14 03:42:44
问题 The following code works with all YouTube domains except for youtu.be . An example would be: http://www.youtube.com/watch?v=ZedLgAF9aEg would turn into: ZedLgAF9aEg My question is how would I be able to make it work with http://youtu.be/ZedLgAF9aEg . I'm not so great with regex so your help is much appreciated. My code is: $text = preg_replace("#[&\?].+$#", "", preg_replace("#http://(?:www\.)?youtu\.?be(?:\.com)?/(embed/|watch\?v=|\?v=|v/|e/|.+/|watch.*v=|)#i", "", $text)); } $text =

php capture group

六眼飞鱼酱① 提交于 2019-12-13 18:42:09
问题 I'm kind of stuck capturing a group with preg_match() in php. This is my pattern: <ns2:uniqueIds>(.*)<\/ns2:uniqueIds> And this is the source: <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"><env:Header/><env:Body><ns2:ListResponse xmlns:ns2="http://censored"><ns2:uniqueIds>censored</ns2:uniqueIds><ns2:uniqueIds>censored</ns2:uniqueIds></ns2:ListResponse></env:Body></env:Envelope> What am I missing? 回答1: While I agree with the people above that tell you to not use regular

Capturing all method arguments default values

天涯浪子 提交于 2019-12-13 11:28:10
问题 I'm working on reverse engineering PHP methods because provided \ReflectionClass mechanism is insufficient for my current project. Currently I want to get using regular expressions method prototypes. I got stuck on retrieving default argument values. I'm providing static method MethodArgs::createFromString() with the contents of method prototype parentheses. It's goal is to get all arguments from string including argument type, name ... and default value and create an instance of itself. So

Regex to split string into array of numbers and characters using PHP

拟墨画扇 提交于 2019-12-13 11:18:12
问题 I have an arithmetic string that will be similar to the following pattern. a. 1+2+3 b. 2/1*100 c. 1+2+3/3*100 d. (1*2)/(3*4)*100 Points to note are that 1. the string will never contain spaces. 2. the string will always be a combination of Numbers, Arithmetic symbols (+, -, *, /) and the characters '(' and ')' I am looking for a regex in PHP to split the characters based on their type and form an array of individual string characters like below. (Note: I cannot use str_split because I want

Remove spaces in string, excluding these in specified between specified characters

☆樱花仙子☆ 提交于 2019-12-13 10:51:27
问题 I have a string: Some string, "it's a nice string". I like it. "some other text" I want remove spaces, excluding there beetween ": Somestring,"it's a nice string".Ilikeit."some other text" How I can goal this? 回答1: You could use regular expressions, or you could cheat and use explode() : $text_before = 'Some string, "it\'s a nice string". I like it. "some other text"'; $text_after = array(); $text_quotes = explode('"', $text_before); for ($i = 0, $max = count($text_quotes); $i < $max; $i++) {

php preg_match item first five character regex [closed]

亡梦爱人 提交于 2019-12-13 09:45:22
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I want to match item id,looks like: a1234... b5678... c9876... ... How can I write a regex only match first five characters and first is alphabet letter, 2-5 is integer number 回答1: preg_match_all('/[a-z]\d{2,5}/', $subject, $result, PREG_PATTERN_ORDER); for ($i = 0; $i < count($result[0]); $i++) { # Matched text