Skype source files with smiles regex patterns - regex

Anyone knows where to get skype source files with regex patterns for smiles?
Want to understand how they are working.
I have spend few days trying to recreate exact smiles recognition and yet haven't figured proper pattern.
Can anyone provide some info about it?
Thanks ;)

I wouldn't do it with regex.
I'd use a Map, where the keys are the smiley characters and the values are the URLs to the smiley pics. Then I'd iterate over the map entries and replace all found keys with the equivalent values.
Unfortunately you are not saying what programming language this is about, so here's a simple Java implementation:
Map<String,String> smileyMap = new HashMap<String, String>();
smileyMap.put(":-)", "simpleSmiley.png");
smileyMap.put(":-(", "sadSmiley.png");
// etc.
String text = null;// wherever you get the text from
for(Entry<String, String> entry : smileyMap.entrySet()){
text=text.replace(entry.getKey(),
"<img src=\"http://my.smiley.server/"+ entry.getValue() + "\" />");
}
// now text contains the smileys as HTML images

Related

How do i capture text between two string values? [duplicate]

This question already has answers here:
C# Regex find string between two strings with newLine
(3 answers)
Closed 3 years ago.
The Problem
I have a hobby project that has the aim to sync multiple calendars by requesting the ics file from persons calendars in a group, for the optimal time to plan a meeting. Some sort of lazy way to schedule meetings :)
But i got stuck on reading the ics file for two reasons:
I don't really understand Regex.
And i don't know how to achieve my goal with string manipulation.
The ics file is already structured, so i know that i want to start from BEGIN:VEVENT and gather the that text down to END:VEVENT.
I want every event to in a later stage become a class so i can read the data and come up with a decision to present for the end user.
Background
I tried the regex expression: BEGIN:VEVENT(?:[\w\s\:\#\.\;\-\=\ä\å\ö\\\,\/\#]*)END:VEVENT but that is not a very valid approach. Because it gathers all of the the events and does not divide them into separate groups.
I have been using regexer.com to test my regex expression.
Not code but what i work on
This is some of the text from the ics file:
BEGIN:VEVENT
DTSTART:20121220T180000Z
DTEND:20121220T190000Z
DTSTAMP:20190503T064840Z
UID:SomeHash#google.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN=Name;X-NUM-GUESTS=0:mailto:MailAddress
CREATED:20121212T061002Z
LAST-MODIFIED:20121212T061003Z
LOCATION:ALocation
SEQUENCE:1
STATUS:TENTATIVE
SUMMARY:SomeText
TRANSP:OPAQUE
CATEGORIES:http://schemas.google.com/g/2005#event
END:VEVENT
BEGIN:VEVENT
DTSTART:20121213T143000Z
DTEND:20121213T153000Z
DTSTAMP:20190503T064840Z
UID:SomeHash#google.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN=Name;X-NUM-GUESTS=0:mailto:MailAddress
CREATED:20121212T061146Z
LAST-MODIFIED:20121212T061146Z
LOCATION:ALocation
SEQUENCE:1
STATUS:TENTATIVE
SUMMARY:SomeText
TRANSP:OPAQUE
CATEGORIES:http://schemas.google.com/g/2005#event
END:VEVENT
Desired outcome
Is to get a array of matches with the string text so i can split it even more and create classes.
Disclaimer
As this is a hobby project i want to take on a challenge and not use a plugin or helping library. But links to these are appreciated if i can see how they solve the problem.
try using
BEGIN:VEVENT([\s\S]*?)END:VEVENT
I use Regex101.com for regex, Hope this helps
Regular expressions are usually a good fit for extracting text. But in this simple case you could try something like this:
var preambleLenght = "BEGIN:VEVENT\r\n".Length;
var text = ics.Substring(preambleLenght, ics.LastIndexOf("\r\nEND:VEVENT") - preambleLenght);

Parsing links with regex

I have a problem I can't seem to figure out how to write a regular expression correctly. How to write a regular expression that for example if I have loaded some text the part that interests me is links that end with .m3u or m3u8. For example if i specify this input in my program
Input - player = new Player({"player-id":"1","autoplay":"false","fullscreen":"false","debug":"true","content-volume":"85","ad-volume":"30","ad-load-timeout":"15000","div-id":"videoPlayer","default-quality-index":0,"title":"\u0428\u043f\u0438\u043e\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0435\u043d\u044f \u043a\u0438\u043d\u0443\u043b ","poster":"https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-480p.mp4/thumb-33000.jpg","content":{"mp4":[],"dash":"https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-,480,p.mp4.urlset/manifest.mpd","hls":"https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-,480,p.mp4.urlset/master.m3u8"},"about":"false","key":"4eeeb77181526bedc1025586d43a70fa","btn-play-pause":"true","btn-stop":"true","btn-fullscreen":"true","btn-prev-next":"false","btn-share":"true","btn-vk-share":"true","btn-twitter-share":"true","btn-facebook-share":"true","btn-google-share":"true","btn-linkedin-share":"true","quality":"true","volume":"true","timer":"true","timeline":"true","iframe-version":"true","max-hls-buffer-size":"10","time-from-cookie":"true","set-prerolls":["https://test/j/v.php?id=645"],"max-prerolls-impressions":1});
By using regex the output should be -
https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-,480,p.mp4.urlset/master.m3u8
I have tried writing this regex expression but it parses all links and not the ones that I need. I only need the links tht end with a specific tag
Thank you for your answer in advance
I dont see why there are so much downvotes, maybe the question looked totally different originally.
Using regex only, my solution in ASP.net would be to reverse the text first, then look up for everything between "u3m" until the next occurence of "ptth".
Play with it: http://refiddle.com/nwvu
Regex for m3u8 OR m3u:
(8u3m.+?ptth)|(u3m.+?ptth)
ASP String reversal (from https://forums.asp.net/t/1841367.aspx?Reverse+String+in+asp+net):
string input = TextBox1.Text;
char[] inputarray = input.ToCharArray();
Array.Reverse(inputarray);
string output = new string(inputarray);

How to remove query string ? from image url vb.net

Whats the best way to remove a query string (the question mark variables) from a image url.
Say I got a good image such as
http://i.ebayimg.com/00/s/MTYwMFgxNjAw/z/zoMAAOSwMpZUniWv/$_12.JPG?set_id=880000500F
But I can't really save it properly without adding a bunch of useless checking code because of the query string crap after it.
I just need
http://i.ebayimg.com/00/s/MTYwMFgxNjAw/z/zoMAAOSwMpZUniWv/$_12.JPG
Looking for the proper regular expression that handles this so I could replace it with blank.
It might be simple enough not to worry about regex.
This would work:
Dim cleaned = url.Substring(0, url.IndexOf("?"c))

openxml bulk find and replace words in a template dotx

Im trying to replace "" in a word template using openXML
foreach (XmlNode node in doc.SelectNodes("/descendant::w:t", nsManager))
{
MessageBox.Show(node.InnerText);
}
The above doesnt work, I'm getting broken down parts of the text, e.g. "<" and "sometag" and then ">".
I want to replace the full text
"<sometag>"
Any suggestions?
This blog talks about Search Replace functionality. Link
You can understand the Algorithm or just take sample code and use it. You will need to install Open Xml SDK to use sample code.

Use cases for regular expression find/replace

I recently discussed editors with a co-worker. He uses one of the less popular editors and I use another (I won't say which ones since it's not relevant and I want to avoid an editor flame war). I was saying that I didn't like his editor as much because it doesn't let you do find/replace with regular expressions.
He said he's never wanted to do that, which was surprising since it's something I find myself doing all the time. However, off the top of my head I wasn't able to come up with more than one or two examples. Can anyone here offer some examples of times when they've found regex find/replace useful in their editor? Here's what I've been able to come up with since then as examples of things that I've actually had to do:
Strip the beginning of a line off of every line in a file that looks like:
Line 25634 :
Line 632157 :
Taking a few dozen files with a standard header which is slightly different for each file and stripping the first 19 lines from all of them all at once.
Piping the result of a MySQL select statement into a text file, then removing all of the formatting junk and reformatting it as a Python dictionary for use in a simple script.
In a CSV file with no escaped commas, replace the first character of the 8th column of each row with a capital A.
Given a bunch of GDB stack traces with lines like
#3 0x080a6d61 in _mvl_set_req_done (req=0x82624a4, result=27158) at ../../mvl/src/mvl_serv.c:850
strip out everything from each line except the function names.
Does anyone else have any real-life examples? The next time this comes up, I'd like to be more prepared to list good examples of why this feature is useful.
Just last week, I used regex find/replace to convert a CSV file to an XML file.
Simple enough to do really, just chop up each field (luckily it didn't have any escaped commas) and push it back out with the appropriate tags in place of the commas.
Regex make it easy to replace whole words using word boundaries.
(\b\w+\b)
So you can replace unwanted words in your file without disturbing words like Scunthorpe
Yesterday I took a create table statement I made for an Oracle table and converted the fields to setString() method calls using JDBC and PreparedStatements. The table's field names were mapped to my class properties, so regex search and replace was the perfect fit.
Create Table text:
...
field_1 VARCHAR2(100) NULL,
field_2 VARCHAR2(10) NULL,
field_3 NUMBER(8) NULL,
field_4 VARCHAR2(100) NULL,
....
My Regex Search:
/([a-z_])+ .*?,?/
My Replacement:
pstmt.setString(1, \1);
The result:
...
pstmt.setString(1, field_1);
pstmt.setString(1, field_2);
pstmt.setString(1, field_3);
pstmt.setString(1, field_4);
....
I then went through and manually set the position int for each call and changed the method to setInt() (and others) where necessary, but that worked handy for me. I actually used it three or four times for similar field to method call conversions.
I like to use regexps to reformat lists of items like this:
int item1
double item2
to
public void item1(int item1){
}
public void item2(double item2){
}
This can be a big time saver.
I use it all the time when someone sends me a list of patient visit numbers in a column (say 100-200) and I need them in a '0000000444','000000004445' format. works wonders for me!
I also use it to pull out email addresses in an email. I send out group emails often and all the bounced returns come back in one email. So, I regex to pull them all out and then drop them into a string var to remove from the database.
I even wrote a little dialog prog to apply regex to my clipboard. It grabs the contents applies the regex and then loads it back into the clipboard.
One thing I use it for in web development all the time is stripping some text of its HTML tags. This might need to be done to sanitize user input for security, or for displaying a preview of a news article. For example, if you have an article with lots of HTML tags for formatting, you can't just do LEFT(article_text,100) + '...' (plus a "read more" link) and render that on a page at the risk of breaking the page by splitting apart an HTML tag.
Also, I've had to strip img tags in database records that link to images that no longer exist. And let's not forget web form validation. If you want to make a user has entered a correct email address (syntactically speaking) into a web form this is about the only way of checking it thoroughly.
I've just pasted a long character sequence into a string literal, and now I want to break it up into a concatenation of shorter string literals so it doesn't wrap. I also want it to be readable, so I want to break only after spaces. I select the whole string (minus the quotation marks) and do an in-selection-only replace-all with this regex:
/.{20,60} /
...and this replacement:
/$0"¶ + "/
...where the pilcrow is an actual newline, and the number of spaces varies from one incident to the next. Result:
String s = "I recently discussed editors with a co-worker. He uses one "
+ "of the less popular editors and I use another (I won't say "
+ "which ones since it's not relevant and I want to avoid an "
+ "editor flame war). I was saying that I didn't like his "
+ "editor as much because it doesn't let you do find/replace "
+ "with regular expressions.";
The first thing I do with any editor is try to figure out it's Regex oddities. I use it all the time. Nothing really crazy, but it's handy when you've got to copy/paste stuff between different types of text - SQL <-> PHP is the one I do most often - and you don't want to fart around making the same change 500 times.
Regex is very handy any time I am trying to replace a value that spans multiple lines. Or when I want to replace a value with something that contains a line break.
I also like that you can match things in a regular expression and not replace the full match using the $# syntax to output the portion of the match you want to maintain.
I agree with you on points 3, 4, and 5 but not necessarily points 1 and 2.
In some cases 1 and 2 are easier to achieve using a anonymous keyboard macro.
By this I mean doing the following:
Position the cursor on the first line
Start a keyboard macro recording
Modify the first line
Position the cursor on the next line
Stop record.
Now all that is needed to modify the next line is to repeat the macro.
I could live with out support for regex but could not live without anonymous keyboard macros.