Let's imagine we have this string: string Transport = &quot;car motorcycle motorcycle plane train&quot;;  How can I find the first occurence of the word &quot;motorcycle&quot; in this string and change it in the original string to something else instead of having to create a separate string using LINQ?
50428
I want to replace the first occurrence in a given string.   How can I accomplish this in .NET?
1707
I have several strings in the rough form:  [some text] [some number] [some more text]   I want to extract the text in [some number] using the Java Regex classes.  I know roughly what regular expression I want to use (though all suggestions are welcome). What I'm really interested in are the Java calls to take the regex string and use it on the source data to produce the value of [some number].  EDIT: I should add that I'm only interested in a single [some number] (basically, the first instance). The source strings are short and I'm not going to be looking for multiple occurrences of [some number].
111517
I need to find all occurrences of AAsomeArbitraryStringBB and replace it with CCsomeArbitraryStringDD.  So  AAHelloBB Text AAByeByeBB   becomes  CCHelloDD Text CCByeByeDD.   It's important to note that the replacement string contains part of the search string.
47388
In C#, can I convert a string value to a string literal, the way I would see it in code? I would like to replace tabs, newlines, etc. with their escape sequences. If this code: Console.WriteLine(someString);  produces: Hello World!  I want this code: Console.WriteLine(ToLiteral(someString));  to produce: \tHello\r\n\tWorld!\r\n
83873
Is it possible to do something like this?  var pattern = /some regex segment/ + /* comment here */     /another segment/;   Or do I have to use new RegExp() syntax and concatenate a string? I'd prefer to use the literal as the code is both more self-evident and concise.
3909
Is there a way to achieve the equivalent of a  in javascript regular expressions?  I need to match a string that does not start with a specific set of characters.  It seems I am unable to find a regex that does this without failing if the matched part is found at the beginning of the string.  Negative lookbehinds seem to be the only answer, but javascript doesn't have one.  EDIT: This is the regex that I would like to work, but it doesn't:  (?&lt;!([abcdefg]))m  So it would match the 'm' in 'jim' or 'm', but not 'jam'
108057
What's the best way to extract the first word of a string in sql server query?
4602
Example (note the case):  string s = "Hello world!"; String s = "Hello world!";   What are the guidelines for the use of each? And what are the differences?
62677
I am writing a Java utility which helps me to generate loads of data for performance testing.  It would be really cool to be able to specify a regex for Strings so that my generator spits out things which match this.  Is there something out there already baked which I can use to do this?  Or is there a library which gets me most of the way there?  Thanks
17417
Is there a simple way to convert a string to Title Case? E.g. john smith becomes John Smith. I'm not looking for something complicated like , just (hopefully) some kind of one- or two-liner.
123694
I want to search for string that have  [RT]"anything"D  which mean first character can either be R or T  and the next can be anything until D is appear what should I use is it "egrep"?
46850
I'm trying to get a case-insensitive search with two strings in JavaScript working.  Normally it would be like this:  var string="Stackoverflow is the BEST"; var result= string.search(/best/i); alert(result);   The /i flag would be for case-insensitive.  But I need to search for a second string; without the flag it works perfect:  var string="Stackoverflow is the BEST"; var searchstring="best"; var result= string.search(searchstring); alert(result);   If I add the /i flag to the above example it would search for searchstring and not for what is in the variable "searchstring" (next example not working):  var string="Stackoverflow is the BEST"; var searchstring="best"; var result= string.search(/searchstring/i); alert(result);   How can I achieve this?
47023
Say I have the string "User Name:firstname.surname" contained in a larger string how can I use a regular expression to just get the firstname.surname part?  Every method i have tried returns the string "User Name:firstname.surname" then I have to do a string replace on "User Name:" to an empty string.  Could back references be of use here?  Edit:  The longer string could contain "Account Name: firstname.surname" hence why I want to match the "User Name:" part of the string aswell to just get that value.
56815
Is there a way to specify a regular expression to match every 2nd occurrence of a pattern in a string?  Examples   searching for a against string abcdabcd should find one occurrence at position 5 searching for ab  against string abcdabcd should find one occurrence at position 5 searching for dab  against string abcdabcd should find no occurrences searching for a against string aaaa should find two occurrences at positions 2 and 4
64488
I am trying to parse url-encoded strings that are made up of key=value pairs separated by either &amp; or &amp;amp;.   The following will only match the first occurrence, breaking apart the keys and values into separate result elements:  var result = mystring.match(/(?:&amp;|&amp;amp;)?([^=]+)=([^&amp;]+)/)   The results for the string '1111342=Adam%20Franco&amp;348572=Bob%20Jones' would be:  ['1111342', 'Adam%20Franco']   Using the global flag, 'g', will match all occurrences, but only return the fully matched sub-strings, not the separated keys and values:  var result = mystring.match(/(?:&amp;|&amp;amp;)?([^=]+)=([^&amp;]+)/g)   The results for the string '1111342=Adam%20Franco&amp;348572=Bob%20Jones' would be:  ['1111342=Adam%20Franco', '&amp;348572=Bob%20Jones']   While I could split the string on &amp; and break apart each key/value pair individually, is there any way using JavaScript's regular expression support to match multiple occurrences of the pattern /(?:&amp;|&amp;amp;)?([^=]+)=([^&amp;]+)/ similar to PHP's preg_match_all() function?  I'm aiming for some way to get results with the sub-matches separated like:  [['1111342', '348572'], ['Adam%20Franco', 'Bob%20Jones']]   or   [['1111342', 'Adam%20Franco'], ['348572', 'Bob%20Jones']]
51825
I have the name of the "sort by property" in a string. I will need to use Lambda/Linq to sort the list of objects.  Ex:  public class Employee {   public string FirstName {set; get;}   public string LastName {set; get;}   public DateTime DOB {set; get;} }   public void Sort(ref List&lt;Employee&gt; list, string sortBy, string sortDirection) {   //Example data:   //sortBy = "FirstName"   //sortDirection = "ASC" or "DESC"    if (sortBy == "FirstName")   {     list = list.OrderBy(x =&gt; x.FirstName).toList();       }  }    Instead of using a bunch of ifs to check the fieldname (sortBy), is there a cleaner way of doing the sorting Is sort aware of datatype?
1424
I have the string   a.b.c.d   I want to count the occurrences of '.' in an idiomatic way, preferably a one-liner.  (Previously I had expressed this constraint as "without a loop", in case you're wondering why everyone's trying to answer without using a loop).