2040001 to 2040021 Inventory Stocks-Apr-21
how to fetch april 21 in it.HOW TO REMOVE REST ALL CHARACTERS
You can try with regular expression
System.Text.RegularExpressions.Regex.Match(YourString,"(?<=-)\S+").Tostring
Regards
Gokul
Hi,
use below expression
extractedValue = System.Text.RegularExpressions.Regex.Match(inputString, “(\w{3}-\d{2})”).Value
and if you don’t have “-” then use below expression for Apr 21
extractedValue = System.Text.RegularExpressions.Regex.Match(inputString, “(\w{3}-\d{2})”).Value.Replace(“-”, " ")
hi
use regex expression
stroutput=system.text.regularexpression.regex.match(input,“(?<=-)”).value
cheers
strinput="2040001 to 2040021 Inventory Stocks-Apr-21"
System.Text.RegularExpressions.Regex.Match(strinput,"[A-Za-z]+\-\d+").Value
Hope it helps!!
Alternative Regular expression
System.Text.RegularExpressions.Regex.Match(YourString,"[A-Za-z]+\W\d{2}$").Tostring.Replace("-"," ")
You can try this expression it will remove all expect the apr 21
System.Text.RegularExpressions.Regex.Match(str_InPut,"\b[A-Za-z]{3}-\d{2}\b").Value.Replace("-"," ")
OutPut : -
System.Text.RegularExpressions.Regex.Match(strinput,“[A-Za-z]+-\d+”).Value
what is the meaning of this expression
(System.Text.RegularExpressions.Regex.Match(str,“((?<=Stocks-).*)”).Value).Replace(“-”," ")
The regular expression "[A-Za-z]+-\d+"
is used to match a specific pattern in a given input string. Here’s the breakdown of its meaning:
[A-Za-z]
: This part of the expression matches any uppercase or lowercase letter from ‘A’ to ‘Z’ (uppercase) and ‘a’ to ‘z’ (lowercase). In other words, it matches alphabetic characters.+
: The plus symbol indicates that the previous character class or expression should appear one or more times. In this case, it’s specifying that one or more alphabetic characters should be present.-
: This is a literal hyphen character. It specifies that a hyphen should appear in the input string.\d
: The\d
represents a digit. It matches any numeric digit from 0 to 9.
So, when you use System.Text.RegularExpressions.Regex.Match
with the pattern "[A-Za-z]+-\d+"
, it searches for a substring within the input string that matches the following pattern:
You can use the Match and replace regular expression to get the required output.
- Assign -> Input = "2040001 to 2040021 Inventory Stocks-Apr-21"
- Assign -> Output = System.Text.RegularExpressions.Regex.Match(Input.ToString,"((?<=\-).*)").Value.Replace(System.Text.RegularExpressions.Regex.Match(Input.ToString,"(-)").Value,"")
- Assign -> OutputDate = DateTime.ParseExact(Output,"MMM yy",System.Globalization.CultureInfo.InvariantCulture).ToString("MMMM yy")
Check the below workflow for better understanding.
Hope it helps!!
Hope its clarified
can you explain me the expression according to the input?
System.Text.RegularExpressions.Regex.Match(str_InPut,“\b[A-Za-z]{3}-\d{2}\b”).Value.Replace(“-”," ")
i/p - 2040001 to 2040021 inventory stocks-apr-21
"\b[A-Za-z]{3}-\d{2}\b" is a pattern used to match specific text in a string it will mactch "apr-21"
\b :This is a word boundary anchor. It ensures that the pattern is matched as a whole word
[A-Za-z]{3} it i will match the capital aswell as small letters
-: This matches a hyphen character.
\d : it will match the numbers
\b
: Another word boundary anchor
so basically for your provide input
i/p - 2040001 to 2040021 inventory stocks-apr-21
it will exactly matches the apr- 21 ,so after if you need you can remove the (-)
which i provide the regex expression above
hope its cleared for you
System.Text.RegularExpressions.Regex.Match(YourString, "[A-Za-z]+\W\d{2}$")
:
System.Text.RegularExpressions.Regex.Match
is a method for performing regular expression pattern matching.YourString
is the input string on which the pattern matching is performed."[A-Za-z]+\W\d{2}$"
is the regular expression pattern.[A-Za-z]+
matches one or more alphabetic characters (both uppercase and lowercase).\W
matches any non-word character (in this case, it can be a punctuation character or a space).\d{2}
matches exactly two digits.$
asserts the end of the string.This regular expression pattern is looking for a sequence of alphabetic characters, followed by a non-word character, and ending with exactly two digits at the end of the input string.
.ToString()
:
- This converts the result of the
Regex.Match
operation into a string. TheMatch
method returns aMatch
object, and this step is converting it to a string representation.
.Replace("-", " ")
:
- This part of the expression replaces any hyphens (“-”) in the resulting string with spaces (" "). It’s using the
Replace
method to perform this substitution.
Try with this one?
Regards
Gokul
why you kept 3 in the expression
for matching of three letters that’s why i have mention
you can try this way also
System.Text.RegularExpressions.Regex.Match(str_InPut,"[A-Za-z]+\-\d+").Value.Replace("-"," ")
if month is more than three characters,how to specify