Replacement in excel sheet by list [closed] - regex

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:

Related

I wanted to remove particular pattern from a string in tcl [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 12 months ago.
Improve this question
hreset_error_status_t2_reg1
htrans_flag_t1_reg2
hsize_flag_error_reg
check_hwdata_reg
I had to write a Tcl script using regex I have to remove error_status, flag, flag_error, and check in the following strings. It has to search the following keywords in the file and have to remove the mentioned keywords in a string.
To remove all those patterns from a string, use regsub -all. If you don't need to use the power of regular expressions, then string map works well too.
set my_str "hreset_error_status_t2_reg1 htrans_flag_t1_reg2 hsize_flag_error_reg check_hwdata_reg"
set my_regex {error_status_|flag_(error_)?|check_}
regsub -all $my_regex $my_str ""
--> hreset_t2_reg1 htrans_t1_reg2 hsize_reg hwdata_reg
or
set my_map {
error_status_ ""
flag_error_ ""
flag_ ""
check_ ""
}
string map $my_map $my_str
--> hreset_t2_reg1 htrans_t1_reg2 hsize_reg hwdata_reg
Note that I put flag_error_ before flag_ in $my_map so that only the flag_ characters in flag_error weren't removed.

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]

VB.net - Strings: Splitting or regex [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 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)

VB.Net find the word in textbox and counting [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to find the specific word in the textbox, and I want to count it.
For example,
There is TextBox which contains "abababababab" (6 ab)
and there is another textbox wich contains "ab"
And I want to get the result : 6.
How can I do it?
You can do it like this:
Dim text As String = "abababababab"
Dim find As String = "ab"
Dim result As Integer = CInt((text.Length - text.Replace(find, "").Length) / find.Length)
also this way :
Imports System.Text.RegularExpressions
+++++++
Dim txt As String
txt = "abababababab"
Dim count As Integer
count = Regex.Matches(txt, Regex.Escape("ab")).Count()
Replace the matching chars in the first string with empty strings, then subtract from the lenght of the original string the length of the resulting string, finally divide by the lenght of the matching string
Dim test = "abababababab"
Dim result = test.Replace("ab", "")
Dim len = (test.Length - result.Length) / "ab".Length
Console.WriteLine(len)