Questions tagged [match]

0

votes
1

answer
9

Views

preg_match first string after string in parentheses

I've looked around for solutions close to this but have not been successful in finding a solution. I'm looking to clean up some legacy code via php_codesniffer but the fixer doesn't fix comments or arrays that go past 80 cols just lets you know about them. I have a solution that works for the commen...
vaene
1

votes
2

answer
110

Views

In Perl, how to match two consecutive Carriage Returns?

Hi StackOverflow buddies, I'm on Windows platform; I have a data file but something wrong happened and (I don't know why) all combinations of "Carriage Return + New Line" became "Carriage Return + Carriage Return + New Line", (190128 edit:) for example: When viewing the file as plain text, it is: W...
katyusza
1

votes
1

answer
47

Views

Extract 5 or 6 Digit Numbers from the string

I am trying to extract 5 or 6 digit numbers only from the string. below are code which i have tried but it is not as expected. $str1 = "21-114512"; //it should return 114512 $str2 = "test12345abcd"; //it should return 12345 $str3 = "12test123456testing"; //it should return 123456 functi...
Juned Ansari
0

votes
0

answer
4

Views

perl6 How to make subrule/regex case-insensitive when used in match?

I am trying to match any keywords in a group. Keywords are in array @b. I am unable to make case-insensitive matches. I have done some testing, and the following script is an example: > my $line = "this is a test line"; this is a test line > my @b = < tes lin > ; [tes lin] > my regex a { || @b }; r...
lisprogtor
1

votes
2

answer
65

Views

Simplify regex match groups with capturing [duplicate]

This question already has an answer here: Capture groups match with quantifier Regexp 3 answers I am trying to match such types of strings (5 different strings). |n||0||0||0||0| |n||n||0||0||0| |n||n||n||0||0| |n||n||n||n||0| |n||n||n||n||n| Where is n is variable, but other zeroes are constants,...
fheoosghalzr
1

votes
2

answer
867

Views

Remove rows from a dataframe that match two columns in another dataframe R

I am struggling to remove rows from a data frame in R, where values from different columns match two values from different columns in a second data frame. For example, given the following pseudo-data: ID1
user6380453
1

votes
2

answer
7.8k

Views

PHP preg_match for validating 10 digit mobile number

I am trying to validate 10 digits mobile number using PHP function preg_match. The below code does not produce any output. Is it the regex wrong? or I am using it incorrectly. I was expecting Hi True in the output. if it matches or Hi False if it does not match. regex taken from https://stackoverflo...
Adarsh Madrecha
2

votes
3

answer
23

Views

Matching multiple strings and join

I am having difficulties with matching multiple strings in r. The dataframe that I have looks like this: Var1 Var2 1 SJDJWK P04TGI7F3;P030Y7Y11;PE35RV747;Q2UKLVVX4 2 ODJSMDK Q2UKLVVX4;PWER00711;PE35RV747;Q2UKLVVX4 3 JDKSAKDJ PE35RV747...
PieterD
1

votes
2

answer
54

Views

Javascript - Match (and replace) value to array of array

After parsing values through Ajax request (GET), I need to replace them with other values -> i.e. multiple postal codes corresponding to the same country code ( "1991,1282,6456" : "Idaho", etc. ) This is what I've done so far : $mapCodes = { '1991': 'Idaho', '1282': 'Idaho', '5555': 'Kentucky',...
Italo
1

votes
3

answer
35

Views

String to array, split by new lines and brackets

I have large string block which I need to split into arrays based on if they're wrapped in brackets or separated by new lines. Input: [this is block this is also same "block" this is same block another same block] new block! another new block! [this is new block this is also a new block] One of the...
daveclever
1

votes
1

answer
37

Views

How to extract specific value between slashes in a URL? [duplicate]

This question already has an answer here: How Do You Parse and Process HTML/XML in PHP? 29 answers I'm working on *.xml file containing pictures. https://images.example.co.uk/products/1835/1835776/large2/29203852.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203856.jpg|https://ima...
Kris
1

votes
3

answer
75

Views

Approximate string matching in php

suppose I need to compare two variables $team="Benfica(U23):Vitoria Guimaraes(U23)"; and $team2="Benfica U23:Vitoria Guimaraes U23"; For my purpouse , $team and $team2 should match ,indeed they are the same fixture, only change U23 with (U23). However preg_match is not so smart like a human, so if I...
gr68
1

votes
4

answer
1.1k

Views

String parsing using strtok in C

I would like to read from a .csv file line by line and then check if the first word of my line matches string_1. If it matches, then I would also like to check if the second word matches string_2. My .csv file contains three fields, namely user, password and type. Here is my code so far: void verify...
iHubble
1

votes
1

answer
5.4k

Views

php preg match a-zA-Z and only one space between 2 or more words

For my PHP script I have this code: if (!preg_match("/[^A-Za-z]/", $usersurname)) $usersurname_valid = 1; This worked untill I realized a surname can be two or more words... doh. Anyone can tell me how to write this code if I want to allow 1 space between two worlds? For example: Jan Klaas is now...
Ivan M
1

votes
3

answer
446

Views

c# regex match var value

I want to match var value between quotes. here's input: bunch of other text, html tags, css var SECURITYTOKEN = "1354010802-f407561a1503fa33e8e316f058c0f0598ce5adad"; bunch of other text, html tags, css result should be 1354010802-f407561a1503fa33e8e316f058c0f0598ce5adad i was trying something lik...
dovydas juraska
1

votes
3

answer
5.1k

Views

Match schedule algorithm, each team play specific number of matches

I have a specific number of teams. I want every team to play exactly 4 matches with 4 different opponents at 4 specified times. The complication arises from that no team can play 2 different matches at the same time. For example if team 1 is playing like this team1 vs team2, team1 vs team3, team1 vs...
Abdalla
1

votes
2

answer
95

Views

Find current count and total count from string using regex

I have a string that contains a lot of information, including a total count and current count. I want to use regex and php to match either [001/100] or (001/100). It can either be wrapped in parentheses or brackets. It may also contain spaces inside the parentheses or brackets ( 001/100). The delimi...
ATLChris
1

votes
4

answer
1.7k

Views

PHP- Regular expression - how to read from Right to left

I have below example $game = "hello999hello888hello777last"; preg_match('/hello(.*?)last/', $game, $match); The above code returns 999hello888hello777, what I need is to retrieve the value just before Last, i.e 777. So I need to read regular expression to read from right to left.
Kiruba Paul
1

votes
2

answer
157

Views

How match a css style text in C #

I meet problematical for "matcher" css style in a text. I want to get the following style: style Search Visio Infrastructure and Applications Regex Used: Regex myRegex = new Regex(@""); I think the problem is style = "color: # fffff" but I just can not understand . Thanks a lot
Mehdi Bugnard
1

votes
1

answer
821

Views

Why preg_match() returns first match at index 1 (not 0) of returned array?

Im working on small website scrapper with cURL. I decided to use preg_match to find header and article content. This is my code: preg_match('@(.*?)@s', $this->website, $this->title); if(sizeof($this->title) > 1) $this->title = trim($this->title[1]); // rewrite first element of array to regular varia...
Kamil
1

votes
2

answer
2.9k

Views

How to filter the first occurrence with preg_match

I'm trying to filter domains from a text file which appear always at first position on each line. File looks like: Domains Users domain1.com User1 domain2.com User2 domain3.com User3 Thats what I tried: preg_match_all('/^[^ ]+/', $file, $matches); It is producing the following re...
Aley
1

votes
1

answer
2.7k

Views

How can I allow single underscores only with preg_match?

How can I allow single underscores only with preg_match? The regex I made below takes double underscores which is not I want... if(!preg_match('/^[a-z0-9\s\_]+$/', $name)) { $error = true; echo ''; } For instance, hello world ok hello_world ok hello__world...
laukok
1

votes
3

answer
2.7k

Views

How do I allow brackets in a php preg_match function call?

I want to allow brackets in my php preg_match function call: preg_match("/[^A-Za-z0-9-_,#@. \/']/",$address). How can this be done?
Sid
1

votes
2

answer
1.8k

Views

php preg_match, matching when 2 words might come in random sequence

Is it possible to match two words that might come in random sequences? Examples: $title = "2 pcs watch for couple"; $title = "couple watch 2 pcs"; Currently I'm using two regexes: if (preg_match("/2( )?pcs/i", $title) and preg_match("/couple/i", $title)) Just want to know if it can be done with only...
Kristian Rafteseth
1

votes
4

answer
4.6k

Views

How to get the last words in a string with preg_match

I'am trying to get the last few words in a string. For the last word I'am using this: $string = "Hallo dies ist ein extrem langer Text den ich gern gekuerz haette, leider bin ich selbst zu doof dafür und mach hier einen test."; $pattern = '/[^ ]*$/'; preg_match($pattern, $string, $result); echo "Th...
hamburger
1

votes
2

answer
77

Views

Struggling with regex PHP?

I am trying to put a regex match in PHP to find whether the string contains any other invalid characters other than the following characters, [email protected]#$%^&*()_-+=\}]{[::'"/>.
user1518659
1

votes
2

answer
4.7k

Views

PHP: How to validate UK landline and mobile numbers?

How can I validate UK telephone numbers? I copied the answer from this site, but this answer only accept mobile number. I want to accept both landline and mobile number. Is it possible? # @reference: http://stackoverflow.com/questions/8099177/validating-uk-phone-numbers-in-php $telephone = "01752311...
laukok
1

votes
1

answer
102

Views

How to display all matches in re.findall for a pattern which has string and number in python

I wanted to extract all matches for the following pattern: pattern = 'link_uid=[0-9]' My string looks like: astr = 'this is test link_uid=23500534 and the second test is link_uid=12345' And I am looking for the following output: link_uid=23500534 link_uid=12345 And when I do re.findall('link_uid=[0-...
user89423
1

votes
2

answer
791

Views

Get youtube/vimeo id with pregmatch

How can I get the video ID for youtube and vimeo videos embed code? A youtube video embed code looks like this: where the ID in this is dbPmWbqAJPs. A vimeo embed code looks like this: where the ID in this example is 62468031. I don't want to replace those exact ids, but rather have a pregmatch/pre...
BRAINBUZZ media
1

votes
4

answer
74

Views

What is this regex supposed to do? ^[\d\D]{1,}$

I'm not exactly a pro when it comes to regex and I have a PHP script that runs things through this regex: ^[\d\D]{1,}$ What does this supposed to do, it seems that it matches everything?
jspicher
1

votes
1

answer
216

Views

preg match all with static string at beginning of pattern

I am putting together a preg match all in PHP with the following string: {{beginning_of_string|:|optional_param|:|http_link}} {{beginning_of_string|:|optional_param|:|text}} {{beginning_of_string}} All three of these possibilities can occur in the overall string, or just a single occurrence. Here...
klye_g
1

votes
1

answer
5.3k

Views

php preg_match for <a href> [closed]

First of all I am new to PHP. Normally I can do preg_match tag for a (.*) and read the content but I could not do the same thing for: 123 Is it possible to preg_match tag for the 123 result when the link is different every time in the tag ? Thanks from now.
Luai Kalkatawi
1

votes
5

answer
3.5k

Views

How to get value inside <a tag using preg match all?

i got html content that need to extract values inside hyperlink tag using preg match all. I tried the following but i don't get any data. I included a sample input data. Could you guys help me fix this code and print all values in front of play.asp?ID=(example: i want to get this value 12345 from p...
user1788736
1

votes
4

answer
14.9k

Views

Sum only matched values from two columns

Hello Everyone, Does anyone know how to sum the Hours from column B (Hours) if column A numbers matched with column E and sum by months. Example, take February data as an example, since only 3000 & 4000 existed in both column A & column E, that's why I need to sum the hours (20+10=30) from column B...
James0419
1

votes
2

answer
302

Views

Makefile machit.vim doesn't work

Given the following simple Makefile: #Makiefile ifeq(,) else endif According to this, it's enough to just include this matchit.vim file, which could be found among bundled plugins. Unfortunately, it doesn't for me. Originally, I thought my other plugins might be conflicting with matchit. However, em...
Albert Netymk
1

votes
3

answer
5.6k

Views

(VBA) Excel : action if content in two columns is matching

A picture is worth a thousand words so to make it clear, here is a picture to illustrate the situation: So I have in a column C some contents (string and integer) from C2 to C16. I have another column G some city names (string) from G21 to G25. Here is what I try to do : I want my method probaCity(...
Phalanx
1

votes
1

answer
2.5k

Views

preg_match Named subpatterns - optional keys

Now trying for hours but now I admit that I'm stuck. I'm trying to match an url pattern for a simple framework. $url = 'controller'; preg_match('/(?P\w+)/', $url, $matches); This works for pages without a slash but i want to match urls like controller/action with optional keys $url = 'controller/act...
user2329731
1

votes
2

answer
1.9k

Views

String filtering in php with preg_match and regular expression

I am creating a simple checker function in PHP to validate strings before putting them into an SQL query. But I can not get the right results the from the preg_match function. $myval = "srg845s4hs64f849v8s4b9s4vs4v165"; $tv = preg_match('/[^a-z0-9]/', $myval); echo $tv; Sometimes nothing echoed to t...
1

votes
1

answer
2.7k

Views

Match whole word/phrase and replace

I'm trying to replace a string with another but the problem is that the string is matching some other string partially. I am trying to create a function that searches each line in another spreadsheet and returns that row if my search phrase is found. Script works wonderfully when used with longer wo...
1

votes
1

answer
62

Views

Correcting an illegal PCRE regex in PHP

Update 5/26 I've fixed the behavior of the regular expressions that were previously contained in this question, but as others have mentioned, my syntax still wasn't correct. Apparently the fact that it compiles is due to PHP's preg_* family of functions overlooking my mistakes. I'm definitely a PCRE...
SISYN

View additional questions