I’m trying for a while now to get started with JQuery, but again I’m stuck with regex.
What I want to achieve is this:
- Bookmarklet that uses JQuery or JS
- Bookmarklet looks at current URL I’m at
- Check If URL contains an ID like this: ‘1.1188651’ (1digit+period+7digits)
- If Check OK then copy ID in clipboard or display in new window
Can this be done?
I’m very thankful for your help.
Oliver
RegEx to test the url:
Also see this jsfiddle.
To also get the id:
Also see my second jsfiddle.
=== UPDATE ===
So the bookmarklet could be:
javascript:prefix for the bookmarklet;window.location.hrefis the current url;sId=/\d\.\d{7}/.exec(...)saves the regex result insId;if(>regex<!==null) {...}checks if regex has matched;alert(sId);shows the id in a “new window”.=== UPDATE 2 ===
If the format is
12345678(eight digits) and you want a.after the first digit, you can use following bookmarklet: