Reputation: 143
I have an object which contains the following string "XXXXyyyy!!!!zzzz"
XXXX
- never the same, will always change, it may be a million characters long
yyyy
- will never change, exact number of characters all the time
!!!!
- this is the data I want to result with after I clean the string. This data will always change as well
zzzz
- will never change, exact number of characters all the time
so if:
string = "XXXXyyyy!!!!zzzz"
string.gsub("zzzz","")
# => "XXXXyyyy!!!!"
What can I do next to get just "!!!!"
. How can I use 'yyyy'
, which is static, to erase "XXXXyyyy"
and leave only "!!!!"
. I hope this explains my question. Sorry about the last one.
Upvotes: 1
Views: 886
Reputation: 6076
From your first attempt, if you change it to:
string = "if(location.hostname.indexOf( 'edition.' ) > -1) {document.write('May 8, 2011 -- updated 1854 GMT (0254 HKT)');} else {document.write('May 8, 2011 2:54 p.m. EDT');}"
string.gsub(/^.+else.+'(.+)'.+$/, $1)
Should do it.
Upvotes: 1