[Solved] Regular Expression in String [closed]

That’s XML. XML is a bad idea to parse via regular expression. The reason for this is because these XML snippets are semantically identical: <ul type=”disc”> <li class=”MsoNormal” style=”line-height: normal; margin: 0in 0in 10pt; color: black; mso-list: l1 level1 lfo2; tab-stops: list .5in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto”> <span style=”mso-fareast-font-family: ‘Times New Roman’; mso-bidi-font-family: ‘Times New … Read more

[Solved] Using Python regex matches in eval()

You don’t need eval. In fact, you want to avoid eval like the plague. You can achieve the same output with match.expand: mystr=”abc123def456ghi” user_input1 = r'(\d+).+?(\d+)’ user_input2 = r’\2\1′ match = re.search(user_input1, mystr) result = match.expand(user_input2) # result: 456123 The example about inserting 999 between the matches is easily solved by using the \g<group_number> syntax: … Read more

[Solved] Find the highest number between two literal strings using a Regular Expression

You can use this code to extract the numeric portion from the untitledNNN.java file name: Pattern p = Pattern.compile(“^untitled(\\d+)[.]java$”, Pattern.CASE_INSENSITIVE); for (String fileName : fileNames) { Matcher m = p.matcher(fileName); if (!m.find()) { continue; } String digits = m.group(1); … // Parse and find the max } Demo. Since you are OK with throwing an … Read more

[Solved] Capitalization of the first letters of words in a sentence using python code [closed]

.split(sep): Specifically split method takes a string and returns a list of the words in the string, using sep as the delimiter string. If no separator value is passed, it takes whitespace as the separator. For example: a = “This is an example” a.split() # gives [‘This’, ‘is’, ‘an’, ‘example’] -> same as a.split(‘ ‘) … Read more

[Solved] Extract with Specific Prefix and control no. of digits in Regex- R

You could try the below code which uses word boundary \b. Word boundary is used to match between a word character and a non-word character. > library(stringr) > str_extract_all(x, perl(‘\\b(?:[35948]\\d{9}|TAM\\d{5}|E\\d{7}|A\\d{5})\\b’)) [[1]] [1] “3234567890” “5234567890” “9234567890” “4234567890” “8234567890” [6] “TAM12345” “E1234567” “A12345” solved Extract with Specific Prefix and control no. of digits in Regex- R

[Solved] Remove “_100” or “_150” or “_num” alone from the end of string [duplicate]

Please check the following snippet: const s=”marks_old_100″; // remove any number console.log(s.replace(/_[0-9]+$/, ”)); // remove three digit number console.log(s.replace(/_[0-9]{3}$/, ”)); // remove _100, _150, _num console.log(s.replace(/_(100|150|num)$/, ”)); solved Remove “_100” or “_150” or “_num” alone from the end of string [duplicate]

[Solved] I have built a regex but there is an issue [closed]

/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?:[a-zA-Z0-9]{8,})$/ (click for diagram) I assumed you meant at least 8 characters. If not, then you need {8} (exactly 8) instead of {8,} (at least 8) I assumed “no special characters” means only alphabetic and numeric characters, [a-zA-Z0-9] if any other characters are to be allowed, then you can add them here. Tests here: https://regex101.com/r/QW2qbo/1/ … Read more

[Solved] i need regular expression for org.sqlite.SQLiteException: [SQLITE_CONSTRAINT_UNIQUE] A UNIQUE constraint failed

Introduction The org.sqlite.SQLiteException: [SQLITE_CONSTRAINT_UNIQUE] A UNIQUE constraint failed error is a common issue when working with SQLite databases. This error occurs when a unique constraint is violated, meaning that a value is being inserted into a column that already contains the same value. To solve this issue, a regular expression can be used to check … Read more

[Solved] regular expression to extract only Customerid and Data (bytes) and save in list?

For this example, I used your two lines of input data pasted three times in the data.txt input test file: Python: import re data = {} regex = re.compile(r’CustomerId:(\d+).*?Size:(\d+)’); with open(‘data.txt’) as fh: for line in fh: m = regex.search(line) if (m.group(1) and m.group(2)): cust = m.group(1) size = m.group(2) try: data[cust] += int(size) except … Read more