string-matching

tsql last “occurrence of” inside a string

泪湿孤枕 提交于 2019-12-09 03:32:26
问题 I have got field containing comma separated values. I need to extract the last element in the list. I have tried with this: select list_field, LTRIM(RTRIM(right(list_field, len(list_field) - CHARINDEX(',',list_field)))) But it returns the last part of the list just starting after the first comma occurrence. For example, a,b returns b a,b,c returns b,c I would like to use a regex like pattern. Is it possible in TSQL (sql server 2008)? Any other clues? 回答1: Find the last , by reversing the

Fastest way to reverse a string in python

喜欢而已 提交于 2019-12-09 01:42:43
问题 I was able to come up with two different ways to reverse a string in Python. Commonsense dictates that the more lines of code the slower it runs. I made the following lines of code: Code1 "".join(reversed(map(lambda x:x,st))) Code2 st[::-1] These give similar performance. For a 20000 long string I am not able to see a difference of even a millisecond in performance. I think the first one should be a slower approach because it performs 3x more operations. Question Why am I not seeing a

How Can I Implement A Standard Set of Hyperlink Detection Rules in Delphi

对着背影说爱祢 提交于 2019-12-08 19:16:14
问题 I currently do automatic detection of hyperlinks within text in my program. I made it very simple and only look for http:// or www. However, a user suggested to me that I extend it to other forms, e.g.: https:// or .com Then I realized it might not stop there because there's ftp and mailto and file, all the other top level domains, and even email addresses and file paths. What I think is best is to limit it to what is practical by following some often-used standard set of hyperlink detection

Check if a string ends with a suffix in Emacs Lisp

拥有回忆 提交于 2019-12-08 17:05:55
问题 Is there a function that checks that a string ends with a certain substring? Python has endswith: >>> "victory".endswith("tory") True 回答1: Just install s.el string manipulation library and use its s-suffix? predicate: (s-suffix? "turn." "...when it ain't your turn.") ; => t But if you refuse you to use this library, you have to write your own function. There is string-prefix-p, which is an analog to Python's str.startswith, in subr.el , and it is just a wrapper around compare-strings.

Delete to end of line after a match, keep lines not matched

隐身守侯 提交于 2019-12-08 16:25:40
问题 I have a file of the following form: interesting text-MIB blah blah blah VERY INTERESTING TEXT interesting text-MIB blah blah blah In each line containing the "-MIB" string, I would like to delete the text following this string, until the end of the line. The following command seems to work as intended: sed -i -n -e 's/-MIB.*$/-MIB/p' ./myfile My problem is that it also deletes the lines where my pattern is not found. Here, the line "VERY INTERESTING TEXT" would be deleted. I am not really

c# string comparison method returning index of first non match

拥有回忆 提交于 2019-12-08 14:40:10
问题 Is there an exsting string comparison method that will return a value based on the first occurance of a non matching character between two strings? i.e. string A = "1234567890" string B = "1234567880" I would like to get a value back that would allow me to see that the first occurance of a matching break is A[8] 回答1: /// <summary> /// Gets a first different char occurence index /// </summary> /// <param name="a">First string</param> /// <param name="b">Second string</param> /// <param name=

I need a regEx to match general URLs

╄→гoц情女王★ 提交于 2019-12-08 11:03:27
问题 I need to test for general URLs using any protocol (http, https, shttp, ftp, svn, mysql and things I don't know about). My first pass is this: \w+://(\w+\.)+[\w+](/[\w]+)(\?[-A-Z0-9+&@#/%=~_|!:,.;]*)? (PCRE and .NET so nothing to fancy) 回答1: According to RFC2396: ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? 回答2: adding that RegEx as a wiki answer: [\w+-]+://([a-zA-Z0-9]+\.)+[[a-zA-Z0-9]+](/[%\w]+)(\?[-A-Z0-9+&@#/%=~_|!:,.;]*)? option 2 (Re CMS) ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]

matching list of substrings to a list of strings in Python

久未见 提交于 2019-12-08 05:11:25
问题 What is a good pythonic way to match a list of substrings to a list of strings, like the following: if 'sub1' in str1 or 'sub2' in str1 or ... 'subN' in str1 or\ 'sub1' in str2 or 'sub2' in str2 or ... 'subN' in str2 or\ ... 'sub1' in strM or 'sub2' in strM or ... 'subN' in strM: One way is to unite them with list comprehension, like this: strList = [str1, str2, ..., strM] subList = ['sub1', ..., 'subN'] if any(sub in str for sub in subList for str in strList): Is there anything better, like

Compare files line by line to see if they are the same, if so output them

独自空忆成欢 提交于 2019-12-08 05:01:06
问题 How would I go about this, I have files which I have sorted the information in, I want to compare a certain index in that file with an index in another, one problem is that the files are enormously large, millions of lines. I want to compare line by line the files I have, if they match I want to input both those values along with other values using an index method. ======================= Let me clarify, I want to take say line[x] the x will remain the same as it is formatted uniformly, I

R - Merging two data files based on partial matching of inconsistent full name formats

筅森魡賤 提交于 2019-12-08 04:28:05
问题 Here is my previous question reposted with R format. I'm looking for a way to merge two data files based on partial matching of participants' full names that are sometimes entered in different formats and sometimes misspelled. I know there are some different function options for partial matches (eg agrep and pmatch) and for merging data files but I need help with a) combining the two; b) doing partial matching that can ignore middle names; c) in the merged data file store both original name