regex

javascript search string contains ' + '

余生长醉 提交于 2021-02-08 06:16:53
问题 i would to search a string into another string but i'm facing an issue. There is my code : reference = "project/+bug/1234"; str = "+bug/1234"; alert(reference.search(str)); //it should alert 8 (index of matched strings) but it alert -1 : so, str wasn't found into reference. I've found what's the problem is, and it seems to be the " + " character into str, because .search("string+str") seems to evaluate searched string with the regex " + " 回答1: Just use string.indexOf(). It takes a literal

Django multiple pks in url

对着背影说爱祢 提交于 2021-02-08 05:47:19
问题 I am currently trying to build an API using the Django Rest Framework. Currently I want to be able to have multiple pks in a single url, but when I try I get an error: django.core.exceptions.ImproperlyConfigured: "^video/(?P[0-9]+)/quiz/(?P[0-9]+)/list/$" is not a valid regular expression: redefinition of group name 'pk' as group 2; was group 1 at position 31 Here are my URLS: url(r'^video/(?P<pk>[0-9]+)/quiz/(?P<pk>[0-9]+)/list/$', views.QuizList.as_view(), name='quizzes-list'), url(r'^video

Automatic whois data parsing

不羁岁月 提交于 2021-02-08 05:21:12
问题 I need to parse WHOIS raw data records into fields. There is no one consistent format for the raw data, and I need to support all the possible formats (there are ~ 40 unique formats that I know of). For examples, here are excerpts from 3 different WHOIS raw data records: Created on: 2007-01-04 Updated on: 2014-01-29 Expires on: 2015-01-04 Registrant Name: 0,75 DI VALENTINO ROSSI Contact: 0,75 Di Valentino Rossi Registrant Address: Via Garibaldi 22 Registrant City: Pradalunga Registrant Postal

Convert a regular expression A that accepts a set of strings to one that accepts all prefixes of the strings that A matches

落爺英雄遲暮 提交于 2021-02-08 05:19:11
问题 Given any regular expression A, is there a way to to transform it to anouther regular expression B, that accepts all the strings and prefixes of strings that A accepts. for example if /apple/ is the given regular expression, is there a generalized way to convert it to /a|ap|app|appl|apple/ 回答1: If you're talking about formal regular expressions (i.e. regular expressions that describe regular languages), then here's a procedure to convert a regular expression into one that accepts prefixes.

How to find and replace all occurrences of “(percentage)%” in a text file and replace with a user supplied Integer

。_饼干妹妹 提交于 2021-02-08 04:59:32
问题 I am trying to parse through a text file with regex finding percentages as strings and replacing the findings with the percentage multiplied by a user supplied integer. If the user inputs 400, then the code should return "120 x 8, 180 x 6, etc" Tried doing a replace but it replaces all findings with the same string. $body = "30% x 8, 45% x 6, 55% x 4, 60% x 2, 65% x 1, 70% x 1, 75% x 1, 80% x 1, 72.5% x 4, 70% x 4, 67.5% x 4, 65% x 4" $regex1 = "(\d+(\.\d+)?%)" $regex2 = "(\d+(\.\d+)?)"

Powershell -replace giving strange behaviour

五迷三道 提交于 2021-02-08 04:56:55
问题 This is driving me nuts! Would appreciate any pointers as to what is going on, please! $alpha = 'aaa.bbb.$connection.ccc.ddd' $s = [regex]::match($alpha,"\$.+?(?=\.)").Value "Alpha is: $alpha" "Matched chunk is: $s" $newChunk = "'" + $s + "'" "New chunk is: $newChunk" $beta = $alpha -replace $s,$newChunk "Beta is: $beta" This produces the following output: Alpha is: aaa.bbb.$connection.ccc.ddd Matched chunk is: $connection New chunk is: '$connection' Beta is: aaa.bbb.$connection.ccc.ddd I am

Removing utm source via php / regex

孤者浪人 提交于 2021-02-08 04:38:22
问题 <?php $before='http://www.urchin.com/download.html? utm_source=google&utm_medium=email&utm_campaign=product'; $after = preg_replace('[?]utm_source=.*/','', $before); echo $after; ?> Hi all, How can I remove UTM tracking from URL via PHP/Regex in the above code example? New to PHP so please explain your answer. Thanks in advance! Edit: Got a bit closer but still getting errors. 回答1: $url = strtok($url, '?'); You can read more about strtok here. Update: If you need to remove only utm_ params,

C# - Regular expression to find a surrogate pair of a unicode codepoint from any string?

删除回忆录丶 提交于 2021-02-08 04:27:55
问题 I am trying to parse a message that possibly contains emojis in it. An example message that could be received looks like: {"type":"chat","msg":"UserName:\u00a0\ud83d\ude0b \n"} What should match is \u00a0 as a single character, and \ud83d\ude0b as a pair. I have regex that can pull individual codes, but not pairs to match the full emoji: \\u[a-z0-9]{4} Is there a clean way to account for any/multiple emojis in a sentence so I can replace the surrogate pair with the function I have? Thanks!

R: Regex_Join/Fuzzy_Join - Join Inexact Strings in Different Word Orders

非 Y 不嫁゛ 提交于 2021-02-08 04:03:45
问题 df1 df2 df3 library(dplyr) library(fuzzyjoin) df1 <- tibble(a =c("Apple Pear Orange", "Sock Shoe Hat", "Cat Mouse Dog")) df2 <- tibble(b =c("Kiwi Lemon Apple", "Shirt Sock Glove", "Mouse Dog"), c = c("Fruit", "Clothes", "Animals")) # Appends 'Animals' df3 <- regex_left_join(df1,df2, c("a" = "b")) # Appends Nothing df3 <- stringdist_left_join(df1, df2, by = c("a" = "b"), max_dist = 3, method = "lcs") I want to append column c of df2 to df1 using the strings, 'Apple', 'Sock' and 'Mouse Dog'. I

Powershell - How to search for Whole Words (or) Exact Matches

梦想的初衷 提交于 2021-02-08 04:01:02
问题 this is my requirement. I need to find if a certain CSS classes is referenced in my Solution which has over 120 aspx pages. This is the command that we wrote gci . -include *.aspx -recurse | select-string -pattern ".rtop" -caseSensitive >> D:\CSSResult.txt However, this matches even words with rtop in middle. That is, if I have a variable named as dirtopy, it comes in the result list. I do not want that. I want it in the result only if an exact match of .rtop is found. How do I do it? Any