w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to add more than one word to ignore in regex Pattern
Your regex is a bit misguided - you've used a character class incorrectly. This term: [build-] is a "character class", and means "any single character of those listed", which us not what you want. A regex that meets your requirements (as a java String) is: "^(?!.*build-)(?!.*someword)FILE\s+fusionapps.*Ess\.xml [A-Z0-9:]+:\d$" This regex uses two anchored negative look-aheads to assert that the character sequences do not appear anywhere in the input. See a live demo on rubular of your examples matching correctly

Categories : Regex

Perl regex to capture text between two anchor words but ignore anchor word in comments
This one is a bit tricky. The idea is usually to distinguish all the possible things that you do want to match, put them in an alternation and repeat. So what do we want to match? a single-line comment: // to the end of the string, no matter what. a block-comment: /* until the next */, no matter what. anything else, as long as it doesn't start endmodule The last part can be accomplished by using a negative lookahead at every position in the repetition. So let's put that together: $content =~ m~ modules+whatever # marks the start of the module (?: # each instance of this alternation matches one kind of # module "token" //.*+ # match a single-line comment | # or /[*] # op

Categories : Regex

Regex - Ignore punctuation at end of string
Your sample code works for me: http://repl.it/J0t/5 The string formatting operator creates #?apple the #? is pretty useless but will allow the expression to match all the following: #apple apple grapple apple will also match the same. If your task is to validate you have a whole word apple which is not part of another word, then I recommend something like apple which matches only #apple and apple from the samples above.

Categories : Python

Python Regex: Question mark (?) doesn't match in middle of string
Regex d? simply means that it should optionally (?) match single digit (d). If you use something like this, it will work as you expect (match single digit anywhere in the string): d

Categories : Python

Optional Ignore White Space in String (from Char set) Regex Python
Try the following: new_string = re.sub(r'w[w ]*w|w', "replace", original_string) w is equivalent to [a-zA-Z0-9_], so [w ] will match word characters, tabs, and spaces. So this regex means "match a word character, followed by any number of word characters or whitespace characters, followed by a word character, OR match a single word character". This way you will match whitespace between words but not the whitespace before or after words.

Categories : Python

Need regex to match word or end of string
Alternations (|) apply to the entire group they're in or to the entire pattern, if they are not in any groups. You haven't grouped your alternation with anything, so your version will match TITLE1:s*?(.+?)TITLE2 or the end of the string and nothing else. You need to group the alternation like this: TITLE1:s*?(.+?)(?:TITLE2|$) It's a little strange to have those two lazy quantifiers together. If you want to allow white space before *STUFF_TO_GET*, s* (no ?) is a little bit more clear: TITLE1:s*(.+?)(?:TITLE2|$)

Categories : Regex

Regex Split String at particular word pattern different different value
Regex or Split deliver accurate performance for clearly defined patterns; the pattern you are looking for is too complex for those methods (the required implementation would be too difficult and, in any case, too rigid). This kind of complex problems should be solved by relying on string analysis. Sample code delivering the expected result with your input string (or equivalent ones): Public Class Form1 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim inputString As String = "select * from EmpInfo where age in (select age from Emp_pns where age >= 60 ), active='A' and rownum < 15" Dim whereString As String = inputString.Substring(inputString.ToLower().IndexOf("where") + "where".Length, inputString.Length - (inputStri

Categories : Asp Net

using regex to select a string pattern not containing a word
This works for me, though the lookarounds aren't my strong point, so there may be a more efficient way of doing it: JS var str = '<img class="alignnone " blabla /> <img class="dddd " blabla /> <img style="blalbla" id="img_menu"/>'; str.match(/(?!<img.+?id="img_menu".*?/>)<img.+?/>/g); //["<img class="alignnone " blabla />", "<img class="dddd " blabla />"] Fiddle PHP <?php $code = '<img class="alignnone " blabla /> <img class="dddd " blabla /> <img style="blalbla" id="img_menu"/>'; $newStr = preg_replace('/(?!<img.+?id="img_menu".*?/>)<img.+?/>/','[matched_img]',$code); var_dump(htmlentities($newStr)); ?> Output: string(92) "[matched_img] [matched_img] <img style="blalbla" id="img_menu"/>"

Categories : PHP

regex is very slow, how to check if a string is only with word chars fast?
The only thing i see is to change your pattern to: ^\w++$ but i am not a java expert explanations: I have added anchors (ie ^ $) that increases the performances of the pattern (the regex engine fails at the first non word character until it encounters the end). I have added a possessive quantifier (ie ++), then the regex engine doesn't matter of backtrack positions and is more fast. more informations here.

Categories : Java

Android I Need 1 Superscript Character in the MIDDLE of a String in the Middle of an Array
I am using HTML Link here. The superscript html tags <sup></sup> tags are used to introduce the superscript notation which "6" (simplest) regular exp is used to replace all instances of 6 to 6. I am sure that you can come up with better and much more powerful regexes to control the output. This is code you should try: @Override public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; Cad_listHolder holder = null; if (row == null) { LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, parent, false); holder = new Cad_listHolder(); holder.txtTitle1 = (TextView)row.findViewById(R.id.cad_name); holder.txtTitle2 = (TextView)row.findVi

Categories : Java

Ignore REGEX in MVC model or Select another REGEX depending upon User input
There are a few different options for you: Create a 100% custom validation attribute that combines the Required and RegularExpression attributes to your needs. So inside that custom attribute you would do all the validation that you need and compare the value to the Country property to selectively apply the RegEx as needed. Create a different postcode attribute per country that you care about and use something like the `RequiredIfAttribute (see RequiredIf Conditional Validation Attribute) to determine which one is actually required. You can then use Javascript to show/hide the appropriate input fields.

Categories : C#

I want to find the word and replace the 3 word after the search string with my desired word in batch script
You were close. See mods to your code below. If you really want the first word after wordB... this will do it. Don't enable delayed expansion if you don't need it because that just messes you up if there are ! in the text. @echo off SET InFile=test.txt FOR /F "tokens=*" %%A IN ('FINDSTR "wordA" "%InFile%" ^| FINDSTR "wordB"') DO CALL :FindString "%%A" pause goto :eof :FindString SET String=%~1 SET String=%String:*wordA =% SET String=%String:wordB =% FOR /F "tokens=1" %%A IN ('echo.%String%') DO ECHO.%%A :goto :eof

Categories : Batch File

Extracting a word from the middle of a sentence
You're almost there. You just need to make the pattern match the entire line, and replace it with the name you've captured. You can also eliminate the need for grep by using a lesser-known feature of sed:   Use the -n flag to prevent it from printing each line by default, and add a p command to make it print the matching lines: tail -n 500 $rfile | sed -n 's/.*INFO] (.*)joined .*/1/p'

Categories : Bash

Regex - match either word/digit or only space within a single word
I'd remove s from the character class and use * delimiter: ([a-zA-Z0-9_.,!""'/$-]*) and you can simplify: ([w.,!""'/$-]*)

Categories : Dotnet

How to remove the punctuation in the middle of a word or numbers?
Assuming you meant for my_number to be a string, >>> from string import punctuation >>> my_number = "5,6!7,8" >>> my_word = ["hel?llo", "intro"] >>> remove_punctuation = lambda s: s.translate(None, punctuation) >>> my_number = remove_punctuation(my_number) >>> my_word = map(remove_punctuation, my_word) >>> my_number '5678' >>> my_word ['helllo', 'intro']

Categories : Python

Regex using word boundary but word ends with a . (period)
About your current regex: You don't need to have  after dot since dot is not considered a word character but of course dot needs to be escaped: (?i)i.v. But you do need  before i to make sure it doesn't match e.g. hi EDIT: (Based on your further edits) Try this regex: (?i)i.v.(?=s|$)

Categories : Dotnet

Regex in Java to match a word that is not part of other word
Why not use word boundary? Pattern pattern = Pattern.compile("\bname\b"); String test = "name (name) mynames"; Matcher matcher = pattern.matcher(test); while (matcher.find()) { System.out.println(matcher.group() + " found between indexes: " + matcher.start() + " and " + matcher.end()); } Output: name found between indexes: 0 and 4 name found between indexes: 6 and 10

Categories : Java

std::regex to find word within brackets inside a string, then replace it (and the brackets)
You can use a Regex of something like: @"^[VARIABLEA]$"which will get you a match when you parse through your strings. You can also use the .split() or Regex.split() method to split your strings into arrays on a delimiter SEE: http://www.dotnetperls.com/split Then just replace where you find your match.

Categories : C++

In android how to write a dialogue box for a word in the middle of the text?
You can do so by setting a on click listener on the textView . You will have to create separate textviews for those words for which you want a dialog to appear on click Refer to the following links: How to click or tap on a TextView text How to add click listeners into a string in Android/Java Textview? How to set Listener for TextView? Don't forget to add the following attribute in you textview android:clickable="true"

Categories : Android

How to get a word bounded between `word' with regex? python
Something like this? import re your_line = "(comparative of `good') changed for the better in health or fitness" word = re.search(r"`([^']*)'", your_line).group(1) # good

Categories : Python

How word can be extracted after another word in javascript with regex?
The code is fine. The problem is only in the alert. If the match succeeds, the [match] method returns an array and updates properties of the regular expression object. The returned array has the matched text as the first item, and then one item for each capturing parenthesis that matched containing the text that was captured. Therefore, you should look inside the array: alert(found[1]); This will fail, however, if there is no match, because match returns null in that case. So we need a default value as well: alert((found || [])[1]); One more more suggestion which would have made your problem immediately obvious from the start: use console.log() instead of alert() for debugging.

Categories : Javascript

Regex : Replace ; from word if word does not start with &
Try str.replace(/(^|s)([^&]S+?);(?=$|s)/g, "$1$2*") You cannot do that without capturing groups because that would require a lookbehind assertion, which Javascript doesn't support.

Categories : Javascript

Insert a table into a middle of word processing document (Open XML SDK)
One way to do this may be to use Content Controls as placeholders to insert the table into them from code. var myContentControl = doc.MainDocumentPart.Document.Body.Descendants<SdtBlock>() .Where(e => e.Descendants<SdtAlias>().FirstOrDefault().Val == "myTablePlaceholder").FirstOrDefault(); SdtContentBlock sdtContentBlock1 = new SdtContentBlock(); sdtContentBlock1.Append(table); // Your table myContentControl.Append(sdtContentBlock1);

Categories : C#

Javascript / REGEX: Delete a specific Text (word) starting with a specific letter inside a String with words separated by spaces
How about: str.replace(/sS+/ig,"") Explanation: NODE EXPLANATION ----------------------------------------------------------------------  the boundary between a word char (w) and something that is not a word char ---------------------------------------------------------------------- s 's' ---------------------------------------------------------------------- S+ non-whitespace (all but , , , f, and " ") (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- i is for case-insensitive g is for global

Categories : Javascript

regex for url in image tag with unknown part in the middle using PHP
The regex should be /oldPath(.*?)old filename/ and the replacement would be newPath$1newFilename. I.e. preg_replace('/oldpath(.*?)oldfilename/', 'newpath$1newfilename', originalHTMLstring);

Categories : PHP

Regex which accepts alphanumerics only, except for one hyphen in the middle
You can do this provided you don't want - to be present exactly in middle /^(?=[^-]+-?[^-]+$)[a-zA-Zd-]{9,20}$/ [^-] matches any character that is not -

Categories : Javascript

Regex for limited numbers, unlimited middle dashes?
I think you want something like this: ^d(?:-?d){9}$ Start with a digit. 9 times: optional dash and another digit. Working example: http://rubular.com/r/CrgTOrXC8E

Categories : Javascript

Regex match word groups and parts of previously matched word groups
The issue is that you want to catch overlapping patterns (like "having with" and "with the"). You can do this with a cunning bit of look-ahead. I haven't managed to combine into a single regex with this method yet, but you could do something like this: $text = 'This is an example text to explain the problem I am having with the regular expression'; preg_match_all('/(w{4,})/', $text, $matches1); preg_match_all('/(?=(w{4,}s+w{3,}))/', $text, $matches2); preg_match_all('/(?=(w{4,}s+w{3,}s+w{3,}))/', $text, $matches3); var_dump(array_merge($matches1[1], $matches2[1], $matches3[1]));

Categories : PHP

Use RegEx with IgnoreCase to replace a word but replace using correct found word case
The following has pretty much what you're looking for using Regex. The only consideration is that it keeps the case for the first character, so if you have an upper case in the middle it doesn't look like it will keep that. Replace Text While Keeping Case Intact In C Sharp

Categories : C#

Add regex to ignore /js /img and /css
Negative lookahead? var matches = req.url.match(/^/(?!(js|css))([a-zA-Z]{2,3}([-_][a-zA-Z]{2})?)(/|$)/ ); not followed by js or css

Categories : Javascript

Javascript RegEx pattern to have only alphanumeric and hash(#) symbol in the middle
You can use this: /^[a-z0-9]+#[a-z0-9]+$/i or this if you want an optional hash symbol: /^[a-z0-9]+#?[a-z0-9]+$/i or this for multiple hash symbol: /^[a-z0-9]+[a-z0-9#]+[a-z0-9]+$/i To check only one character (in cases # is optional): 2) /^[a-z0-9]+(?:#[a-z0-9]+)?$/i 3) /^[a-z0-9]+(?:[a-z0-9#]+[a-z0-9]+)?$/i

Categories : Regex

Check if a string starts with the a specific word, if True then print word - PYTHON
You can use str.startswith(): for word in SideMember: if word.startswith('Base'): print word It does exactly as you would expect it to do ;). By the way, you should only use capitalised variable names for classes. Some other methods you probably shouldn't consider, but for the fun of it I included them :p import re for word in sidemembers: if re.search(r'^Base', word) is not None: print word for word in sidemembers: if word[:4] == 'Base': print word

Categories : Python

RegEx search and replace in Eclipse over multiple lines with start and middle and end
if you want to replace action= with listener= inside an a:ajax tag you will need lookbehind instead of lookahead. and you must note that lookbehind in java means you must define the maximum length of the lookbehind range. Something like (?<=a:ajax[wW ]{1,100})action=" with the range of wildcards between 1 until 100, you can increase it if you want by changing the {1,100}. You can do .replaceAll("(?<=a:ajax[\w\W\n]{1,100})action="","listener="") Note about regex lookbehind: Java allowing finite repetition. You still cannot use the star or plus, but you can use the question mark and the curly braces with the max parameter specified. JGsoft engine and the .NET framework RegEx classes, can do full regex inside lookbehind. Javascript not supported lookbehind. Python can use fixed l

Categories : Regex

php: get the word coordinates (sentence num, word num) by position of character in the string
You can do something like: function positionFinder($text, $n) { $s=$text[$n]; $i=0; $sep = array(" ", ".") while (!in_array($text[$n-$i],$sep)) { $s = $text[$n+$i].$s; $i++; } $i=1 while (!in_array($text[$n+$i],$sep)) { $s .= $text[$n+$i]; $i++; } return s; } But would be faster if you create a "positionFinder" array like: function makearray($text) { $sentences = explode(". ", $text); $positionFinder = array(); $slen = 0; for ($i=0; $i<count($sentences); $i++) { $words[$i] = explode(" ", $sentences[$i]); for ($ii=0; $ii<count($words[$i]); $ii++) { $positionFinder[$slen] = $words[$i][$ii]; $slen += strlen($words[$i])+1; //+1 because of " " } $slen

Categories : PHP

Replace A string token in Word document with a word table
Try this: protected void InsertTableAtBookMark(string[][] docEnds, string bookmarkName) { Object oBookMarkName = bookmarkName; Range wRng = WordDoc.Bookmarks.get_Item(ref oBookMarkName).Range; Table wTable = WordDoc.Tables.Add(wRng, docEnds.Length, docEnds[0].Length); wTable.set_Style("Table Grid"); for (int i = 0; i < docEnds.Length; i++) { for (int j = 0; j < docEnds[0].Length; j++) { wTable.Cell(i, j).Range.Text = docEnds[i][j]; wTable.Cell(1, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft; wTable.Cell(1, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter; } } Borders wb = wT

Categories : Dotnet

to get the sub-string which has common starting word and ending word in Excel VBA
The following code reads the string in cell A1 of Sheet1, extracts the substrings of interest, and writes them back to the worksheet in columns B, C & D. Sub ExtractFromLog() Dim str As String Dim entries() As String Dim numEntries As Long Dim i As Long Dim startPos As Long Dim endPos As Long str = Sheet1.Range("A1").Value numEntries = (Len(str) - Len(Replace(str, "fullPath", ""))) / Len("fullPath") ReDim entries(1 To numEntries) startPos = 1 For i = 1 To numEntries startPos = InStr(startPos, str, "fullPath") endPos = InStr(startPos + 1, str, "levelName") - 1 entries(i) = Mid(str, startPos, endPos - startPos + 1) startPos = endPos + 1 Next i Sheet1.Range(Cells(1, 2

Categories : Excel

Insert each word of string into vector and calculating occurrence of each word
you are using iterator for the string, so you iterate through the characters. instead, do a split to the string and iterate the strings in the result std::string word; while( getline(writable, word, ' ') ) { ++src[word]; } for more information read here

Categories : C++

Python string, find specific word, then copy the word after it
It's not the most efficient code in the world, but it is still probably better than a regex: tokens = teststring.split() numlist = [val for key, val in zip(tokens, tokens[1:]) if key == 'number:'] for your follow-up and more general queries: def find_next_tokens(teststring, test): tokens = teststring.split() return [val for key, val in zip(tokens, tokens[1:]) if test(key)] Which could be called as: find_next_tokens(teststring, lambda s: s.startswith('number') and s.endswith(':')) This will help if the keys to search for come from user input: find_next_tokens(teststring, lambda s: s in valid_keys)

Categories : Python

Check the end of a string for valid regex and return the string trimmed of the regex-
You should simply replace: str = 'testfoostringfoo'; var regex = /foo$/; str = str.replace(regex, ''); return str; I removed the if, replace does not affect the string when regex is not found. Keep in mind that match returns an array of matches (['foo']), so the comparison to true fails either way: the condition in if(str.match(regex) == true) is always false. You're looking for if(str.match(regex)) or if(regex.test(str)). Note that trim is somewhat new in JavaScript, and it doesn't take parameters, it just removes whitespaces.

Categories : Javascript

regex to ignore curly brackets
w+ It will match all "word"-characters If you need to generalize it to something that's "between optional curly braces" you could use: {?(.+?)}? which means: {? - an optional curly brace character. It's escaped because { has a special meaning in regular expressions. ? quantifier means 0 or 1 times (thus optional) (.+?) - means anything in non-greedy mode. You need non-greedy here so that regex stops right before the following } (if any) }? - the same as item #1

Categories : C#



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.