last-occurrence

Find last occurrence of comma in a string using regex in javascript

烈酒焚心 提交于 2020-01-24 10:14:29
问题 I have a string which represents an address in Javascript, say, "Some address, city, postcode". I am trying to get the 'postcode' part out. I want to use the split method for this. I just want to know a regex expression that will find the last occurrence of ' , ' in my string. I have tried writing expressions such as address.split("/\,(?=[^,]*$)/"); and address.split(",(?=[^,]*$)"); But these don't seem to work. Help! 回答1: pop() will remove the last element of an array: address.split(",").pop

Bash: how to use sed to replace only the last occurence in a file?

回眸只為那壹抹淺笑 提交于 2019-12-23 12:09:21
问题 Having a file containing repeated commented lines like: # ScriptAlias /cgi-bin/ "somepath" # ScriptAlias /cgi-bin/ "otherpath" I want to add a line only after the last occurence resulting in # ScriptAlias /cgi-bin/ "somepath" # ScriptAlias /cgi-bin/ "otherpath" ScriptAlias /cgi-bin/ "mypath" To do so I'm using this command: sed -i 's:^\(.*ScriptAlias /cgi-bin/.*\):\1 \nScriptAlias /cgi-bin/ "mypath":' file But this results in adding my line after each occurence like: # ScriptAlias /cgi-bin/

finding the last occurrence of an item in a list python

笑着哭i 提交于 2019-12-22 05:28:05
问题 I wish to find the last occurrence of an item 'x' in sequence 's', or to return None if there is none and the position of the first item is equal to 0 This is what I currently have: def PositionLast (x,s): count = len(s)+1 for i in s: count -= 1 if i == x: return count for i in s: if i != x: return None When I try: >>>PositionLast (5, [2,5,2,3,5]) >>> 4 This is the correct answer. However when I change 'x' to 2 instead of 5 I get this: >>>PositionLast(2, [2,5,2,3,5]) >>> 5 The answer here

ANSI SQL 92: find last occurrence of character

强颜欢笑 提交于 2019-12-12 23:14:58
问题 I need a ANSI SQL 92 statement to change all characters following the last '/' character to lower case. On Sybase I would write: update table set col = left(col, len(col)-charindex('/', reverse(col))) || lower(right(col, charindex('/', reverse(col)))) I can find all functions in ANSI SQL 92 but the REVERSE function, that I just use to find the last occurrence of the slash. 来源: https://stackoverflow.com/questions/7241090/ansi-sql-92-find-last-occurrence-of-character

Finding the last occurrence of a word

巧了我就是萌 提交于 2019-12-11 13:46:45
问题 I have the following string: <SEM>electric</SEM> cu <SEM>hello</SEM> rent <SEM>is<I>love</I>, <PARTITION />mind I want to find the last "SEM" start tag before the "PARTITION" tag. not the SEM end tag but the start tag. The result should be: <SEM>is <Im>love</Im>, <PARTITION /> I have tried this regular expression: <SEM>[^<]*<PARTITION[ ]/> but it only works if the final "SEM" and "PARTITION" tags do not have any other tag between them. Any ideas? 回答1: And here's your goofy Regex!!! (?=[\s\S]*

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

finding the last occurrence of an item in a list python

家住魔仙堡 提交于 2019-12-05 06:08:19
I wish to find the last occurrence of an item 'x' in sequence 's', or to return None if there is none and the position of the first item is equal to 0 This is what I currently have: def PositionLast (x,s): count = len(s)+1 for i in s: count -= 1 if i == x: return count for i in s: if i != x: return None When I try: >>>PositionLast (5, [2,5,2,3,5]) >>> 4 This is the correct answer. However when I change 'x' to 2 instead of 5 I get this: >>>PositionLast(2, [2,5,2,3,5]) >>> 5 The answer here should be 2. I am confused as to how this is occurring, if anyone could explain to what I need to correct

SED: multiple patterns on the same line, how to match/parse first one

我们两清 提交于 2019-11-30 11:22:35
I have a file, which holds phone number data, and also some useless stuff. I'm trying to parse the numbers out, and when there is only 1 phone number / line, it's not problem. But when I have multiple numbers, sed matches the last one (even though everywhere it says it should match only match the first pattern?), and I can't get other numbers out.. My data.txt: bla bla bla NUM:09011111111 bla bla bla bla NUM:08022222222 bla bla bla When I parse for the data, my idea was first to remove all the "initial" "bla bla bla" in front of the first phone number (so I search for first occurrence of 'NUM:

SED: multiple patterns on the same line, how to match/parse first one

你。 提交于 2019-11-29 16:59:24
问题 I have a file, which holds phone number data, and also some useless stuff. I'm trying to parse the numbers out, and when there is only 1 phone number / line, it's not problem. But when I have multiple numbers, sed matches the last one (even though everywhere it says it should match only match the first pattern?), and I can't get other numbers out.. My data.txt: bla bla bla NUM:09011111111 bla bla bla bla NUM:08022222222 bla bla bla When I parse for the data, my idea was first to remove all

Replace Last Occurrence of a character in a string [duplicate]

主宰稳场 提交于 2019-11-27 15:59:35
This question already has an answer here: Replace last part of string 11 answers I am having a string like this "Position, fix, dial" I want to replace the last double quote(") with escape double quote(\") The result of the string is to be "Position, fix, dial\" How can I do this. I am aware of replacing the first occurrence of the string. but don't know how to replace the last occurrence of a string String str = "\"Position, fix, dial\""; int ind = str.lastIndexOf("\""); if( ind>=0 ) str = new StringBuilder(str).replace(ind, ind+1,"\\\"").toString(); System.out.println(str); Update if( ind>=0