Reputation: 988
i have a string containing day name, month/day
Sun 6/9 - Sat 6/15
i need to change the sequence of date from above to
sun 9/6 - Sat 15/6
i can do this by writing code to split and then change sequence and join the result. but is there any minimal way to achieve this by using regex or vb.net code.
Upvotes: 2
Views: 148
Reputation: 20139
I dont know the regex syntax for vb.net but your search regex will be: ([a-zA-Z]{3}\s)(\d)/(\d)
(three letters, followed by space followed by digit-slash-digit) and your replace regex will be: \1\3/\2
. If you are familiar with the Unix sed command, it would be
sed -re `s|([a-zA-Z]{3}\s)(\d)/(\d)|\1\3/\2|g`
Upvotes: 0
Reputation: 15010
This regex will find each date group and swap the digits.
regex: (\d{1,2})\/(\d{1,2})
replace with $2/$1
With input text:
Sun 6/9 - Sat 6/15
It yields
Sun 9/6 - Sat 15/6
<script type="text/javascript">
var re = /(\d{1,2})\/(\d{1,2})/;
var sourcestring = "source string to match with pattern";
var replacementpattern = "$2/$1";
var result = sourcestring.replace(re, replacementpattern);
alert("result = " + result);
</script>
Upvotes: 3