preg_replace bbcode with quotes inside does not work - preg-replace

I tried to make a code hide tag for and its working when i write [hide]text[/hide] but not working when I`m write [hide="."]text[/hide]. here is my code:
#\[hide](.*)\[\/hide\]#siU
when I change the code for this line -
#\[hide=(.*)](.*)\[\/hide\]#siU
it not working for me.
can anyone tell me whats is the problem? thanks.

Make the first .* non greedy: .*?.

Change the first .* to a more specific expression. If quotes are necessary in your markup you could write
#\[hide="([^"]*)"](.*)\[\/hide\]#siU
or if not
#\[hide=([^\]])*](.*)\[\/hide\]#siU
To make your first version working togeher with your second but some brackets around the additional part with a following ?:
#\[hide(="([^"]*)")?](.*)\[\/hide\]#siU

Related

Find/Replace AMPScript

Is there a method to Find/Replace using AMPScript? I want to use AMPScript to search through an email to find sections of copy and replace them with alternative copy. I have been using the REPLACE() function but I have been unable to use it in this manner. Its requiring that I have a variable and that variable is then used through %%=v(#var)=%% to output when rendering the email. But it does not search the email body for the appropriate copy. 
This is one part of a larger project that uses the Sales Console to at first display the copy and then trying to using this functionality in Content Builder to change copy. 
​​​​​​​If anyone has any suggestions it would be appreciated as Im going in circles looking for solutions.  

Comma below footer on Gatsby site

I have a comma below my footer on a Gatsby site and I cannot find its source. It is at the end of the wrapper div with id "___gatsby". I have searched all component files and a bunch of other files to no avail. Going through all previous Git versions to find the change would be very burdensome at this point. Perhaps someone has an idea, based on the DOM structure below, where to best search for the comma?
Thanks.
I found it.
It turns out that a rogue character in gatsby-browser.js, in this case a comma after a closing tag, will be added in this way to the end of the #___gatsby div. In this case I overlooked the comma even through search because the comma was at the end of a long line of code and so did not appear visually in the search results list.
Use the find & replace functionality (or even just find) of your IDE/text editor and use the following regular expression:
\s,|,\s,
Here you have a working example of that regex: https://regexr.com/6hogi

Failed to convert excel to pdf using documents4j

i'm trying to convert an excel file to pdf using documents4j.
when trying to do so i'm getting the following error:
this is the code i'm running:
can anyone please tell me why do i get the VB exception and how to overcome it?
Thanks.
Your file is in a folder C:\pdf\newPDF.pdf but you are not escaping the second backslash properly. You are instead adding a newline character: \n. You can already tell by the formatting.
Ideally - when I find the time - I will better validate the input at some point.

removing line numbers for copied code in eclipse

I am wondering if I have some code with line numbers embedded,
1 int a;
2 MyC b;
3 YourC c;
etc., and then I copy them and try to paste them in Eclipse, how to get rid of these line numbers to make the source code valid? Is there any convenient way, or a short-cut key?
Thank you.
Simply use the Alt+Shift+A (Eclipse 3.5 M5 and above) shortcut to toggle block selection mode. Then select the column with line numbers and delete it!
To make it easier you could setup a macro, but for that you need additional plug-in. I'm not aware of how to do it even easier.
Try this link. This is a dynamic online tool, where it is very easy to just copy paste code and get code without line numbers:
http://remove-line-numbers.ruurtjan.com/
You could use some script to do the work. For instance, using sed
I removed line numbers by find and replace with regular expression option.
Replacing regular expression \d+\s\s with empty string where \d+ means any combination of numbers and \s is actually a space (This is to avoid any numbers present in the code).
Best way is use SED command. Here you can specify as many as digit you want to replace.
in below example open copied code in VI editor and assuming its containing upto 1000 lines.
:%s/^[0-9][0-9|10-99|100-999]//g
if you want to use more lines then put one more or condition.

Highlight pdf line

Please can any one help me. I am really stuck I don't know how to highlight particular line of pdf. It would be better if any one can provide me sample code or pseudo code
Thanks
This is not trivial.
To do this, I'd render the PDF contents into one layer, and somehow get the position of the said line/object using the CoreGraphics PDF parser (or some other way). After that, you highlight the said object using your own drawing code.
Just highlighting a particular line is quite difficult.
If you need search and highlight, please try FastPDFKit. I played with it for a while and it's quite good as a pdf reader.
http://mobfarm.eu/fastpdfkit
I'm working on the same thing at the moment and it's not trivial indeed.
From what I can figure out you need to load the text and arrange it in lines first. If you are using Poppler, the Poppler.Page.textList() will provide you with a list of TextBoxes and a TextBox.hasSpaceAfter() will tell you the end of line when returning False.
I am using the Qt4 frontend, so the each TextBox has a QRect from which I can figure out where to highlight a word. Highlighting a line is more or less lirstWordOfLine.geometry().united(lastWordOfLine.geometry()) which will provide the geometry of the line to highlight.
Now what I can't figure out is how to save the coordinates of the highlights in the document.