VB.net - Strings: Splitting or regex [closed] - regex

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
how can I split or use regex for the results of this msgbox to only get:
"maricruz.tinajero"
I thought about removing all new lines so it's only on one line and then using an index number to get the position of the string I want but im still trying to figure that out.

Try this:(str represents your string above)
Dim obj = str.Substring(str.LastIndexOf("\") + 1)

Forget about using Split or Regex for this:
Dim idx As Integer = msg.LastIndexOf("\"c)
Dim user As String = msg.SubString(idx + 1)

Related

regex find string, parse next string to add character in beginning and end of [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have to change a couple of thousand lines of code. Looking for a quick way ;)
Code in PHP $lang[_SAVE] to be altered to $lang['_SAVE']
I need to find [_ and replace it with ['_ and then replace next ] with ']
regex from cmd line in debian would be prefered ;)
EDIT: I need to replace whats between $lang[_ and ] with '<string between $lang[_ and ]>'
Fixed it with:
<?php
$it = new RecursiveDirectoryIterator(".");
// Loop through files
foreach(new RecursiveIteratorIterator($it) as $file) {
if ($file->getExtension() == 'php') {
$content=file_get_contents($file);
$found = preg_replace('/(?<=lang\[)(_.*?)(?=])/', "'$1'", $content);
file_put_contents($file, $found);
}
}
?>
with a bit of help of https://www.phpliveregex.com/#tab-preg-replace
It traverse the files recursively and looks for whats between lang[_ and next ] and replaces that value with '<found value>'

Regex Match in between Strings [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I using Regex to extract a pattern which is of the form [a-zA-z][0-9]{8} Ex:K12345678
I need to extract this pattern from a string and this pattern should be matched properly
I tried the below but my testcase if failing for this scenario
This is my Regex /[a-zA-Z][0-9]{8}/g
phonne number:9978434276K12345678:My pattern
For this scenario it is failing.
My Sample Code
const expression = /[a-zA-Z][0-9]{8}/;
const content = "phone number:9978434276K12345678:My pattern"
let patternMatch = content.match(expression);
The expected output is K12345678.The Regex which I wrote does not handle this.
You can use String.match(Regex)
"9978434276K12345678".match(/[a-zA-Z][0-9]{8}/)
It returns an array of 4 elements: [String coincidence, index: Number, input: String, groups: undefined]
just stay with the element 0: coincidence and 1: index of the match.
and use this just to check that the string matches at least one
/Regex/.test(String)
/[a-zA-Z][0-9]{8}/.test("9978434276K12345678")
It will return true or false
USE expression without quotation marks
const expression = /[a-zA-Z][0-9]{8}/;
const content = "phone number:9978434276K12345678:My pattern"
let patternMatch = content.match(expression);

Split a String by Regex Expression - Split the whole String by the Character '=' only if the Character on the left is not # in Kotlin [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
e.g.
If i have a String like val input = "2+2#=4=test2" should return a List
2+2#=4
test2
order is not important.
You may try splitting using a lookbehind which asserts that what precedes the = sign is not a hash symbol:
val input = "2+2#=4=test2";
val arr = input.split("(?<!#)=".toRegex());
println(arr);
This prints:
[2+2#=4, test2]

Replacement in excel sheet by list [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How to make bulk replacement using regexp patterns from excel range, see my answer below:
Here is my way to make replacement in Excel range using list from another range based on RegExp:
Sub regexpreplace()
Set Myrange = ActiveSheet.Range("A2:A1000") 'range in which we make replace
Set regrange = ActiveSheet.Range("B2:B6") 'range with RegExp pattern
'in range C1:C6 we have pattern for replace
For Each D In regrange
For Each C In Myrange
Set rgx = CreateObject("VBScript.RegExp")
rgx.IgnoreCase = True
rgx.Pattern = D.Value
rgx.Global = True
C.Value = rgx.Replace(C.Value, D.Offset(0, 1).Value)
Next
Next
End Sub
In this code:
A1:A1000 - range with input values
B1:B6 - list of RegExp patterns
C1:C6 - list of output patterns
Some examples of using script:

Check a string has an integer in the last part using Regex [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have few lines
Eg:
word1-word2-word3-1
word1-word2-word3-23
word1-word2-word3-dr
word1-word2-word3-13-4
word1-word2-word3-drg
word1-word2-word3-word4-4
From the above lines i need the following lines by using Regex
word1-word2-word3-1
word1-word2-word3-23
word1-word2-word3-word4-4
ie. The string ending with a "-{int}"
You can use the pattern -\d+$
The pattern means that we are look for;
-\d+ - hyphen and one or more digits
$ Asserts that we are at the line end.
I don't know what language you are writing this in but assuming you are doing it in Javascript. This pattern can be proved using the code below.
"use strict";
var values = [
"word1-word2-word3-1",
"word1-word2-word3-23",
"word1-word2-word3-dr",
"word1-word2-word3-13-4",
"word1-word2-word3-drg",
"word1-word2-word3-word4-4"
];
values.forEach(value => {
if (/.*-(?!\d+-)\w+-\d+$/.exec(value)) {
console.log(value + " has - integer at the end!");
};
});