0
Can someone write a rule using RegExp for me?
Hello, I want to change every Hegira years to Gregorian years. For example: Hegira years + 622 = Gregorian years. I have an incomplete rule. It's (/\b\d{4}\b/g).Thanks!
7 Answers
+ 2
Your rule matches any 4-digit number, which may or may not be a year. What is the context? If you have an idea on the contents of your data perhaps limit to something like [12][089]\d{2} for Gregorian years since 1800 (10dd included ;-), you get the idea)?
For calculating regex may not be the right or only tool. If you are talking web, calculate with PHP or JavaScript or whatever you are using...
+ 2
But what is the actual application? Can you please provide a code sample?
+ 2
Btw I found a converter for inspection at http://www.icoproject.org/conv?l=en
+ 2
Yours teachers code takes the contents of the element with id "wpTextbox1" and change every occurred 4 digits by adding 622.
I suggest you take another look at the JavaScript tutorial on how to call it on click of a button :)
Good luck!
0
::sk:: Thank you for your replying! You are right and your explanation was so good, but i didn't get the idea yet. I meant i can't write the code:( Yes, I'm talking about web. Can you help me?
0
::sk:: In past, my teacher wrote a code for website and i saw it worked properly, but after putting it to Wikipedia's JS file, it didn't work. the following is my teacher codes:
function hejiraYearFix(){
var txt = document.getElementById("wpTextbox1").value;
var res = txt.replace(/\b\d{4}\b/g,function(m){
return parseInt(m)+622});
document.getElementById("wpTextbox1").innerHTML = res;
}
window.hejiraYearFix = hejiraYearFix;
Hope It is a useful code for more explaining.
I want to create a button that change every 4-digit number by one click.
And thank you very much for sharing the above link!
0
::sk:: But i added the button and worked but badly. The button blanked contents and added "undefined" item to the editor!
Can't you help me?