I am trying to replace only " with " within EntryBody
I tried <mt:entrybody replace=""","""> but this seems to not work. Version is MT5.02 and I don't want to use <mt:entrybody encode_html="1">
What I am trying to do is import all entires using CSV(comma separated) format(clients request) and " (quotation mark) inside EntryBody gives me syntax errors. I can't use encode_html because this encodes links() to entities and I don't want that.
Any advice?
One of these should work.
"\"","""
'"','"'
Related
Problem Description
I want to minify a JSON. Meaning:
Desired Result
Before
{
"keyOne": "First Value",
"keyTwo": "Second Value"
}
After
{"keyOne": "First Value", "keyTwo": "Second Value"}
I want to achieve this using RegEx.
What I tried is to replace \s with an empty string. But this leads to the unwanted result that whitespaces also gets removed from values:
Result of Solution attempt
Before
{
"keyOne": "First Value",
"keyTwo": "Second Value"
}
After
{"keyOne": "FirstValue", "keyTwo": "SecondValue"}
Research done / Solution attempts
Searching Google and Stack Overflow, without success since all found questions target other use cases
Honestly just fooling around with basic RegEx knowledge
To clarify the question: I do not want to do this in JavaScript. I know I can go to the console and run something like copy(JSON.stringify(<the-json>)).
I want to quickly do this in an editor, in this case Webstorm using the Replace Tool – without installing any plugins or switching tools.
Final solution
To steps are needed:
Replace \n with an empty string. This removes linebreaks
Replace \s+" with " to remove whitespances.
You need two steps to achieve that in webstrom:
first replace \n with (nothing!) to remove line breaks;
then \s{2}" with " to remove two whitespaces before each key;
The way object is shown in JS isn't related to the way you can handle it;
{\n
"keyOne": "First Value",\n
"keyTwo": "Second Value"\n
}
the \n characters here are shown to make it more human readable, they don't actually exist in the object itself;
const data = {
"keyOne": "First Value",
"keyTwo": "Second Value"
};
console.log(JSON.stringify(data))
thus you can't apply regex to a regular JavaScript object;
however (very unlikely) if you have a string representation of an object (from somewhere?)
you can apply regex to achieve the result you want like shown in the snippet below:
const strObj = `{
"keyOne": "First Value",
"keyTwo": "Second Value"
}`;
//since it is string we can't access it like normal js objects
console.log(strObj["keyOne"]);
console.log(typeof strObj, strObj);
//replacing the new line with nothing to make it linear
let result = strObj.replace(/\n/g,"")
console.log(typeof result, result);
//casting result to a valid json to an actual js object
let castedResult = JSON.parse(result);
// it will be shown as human readable since its normal object :)
console.log(typeof castedResult,castedResult);
//accessing one its attributes since its normal object now
console.log(castedResult.keyOne);
The following Code fails in IE and Firefox. Never had a problem with Chrome.
foundElement = driver.FindElement(By.Id("btn-GDR"));
It says couldn't find the element #btn\-GDR
Why is Selenium inserting a \ before the -?
Firefox 65.0.2 Version
IE 11.0.9600.19301
EDIT: More Info: I've tried using
"btn\x2dGDR" meaning \x2d is the "-" symbol (ASCII in HEX) but it does not solve the problem. It always insert a "\" before it.
As Selenium converts the different Locator Strategies into it's effective CSS selectors as per the switch - cases the values of class name, id, name, tag name, etc are converted through:
cssEscape(value);
The cssEscape(value) is defined as:
private String cssEscape(String using) {
using = using.replaceAll("([\\s'\"\\\\#.:;,!?+<>=~*^$|%&#`{}\\-\\/\\[\\]\\(\\)])", "\\\\$1");
if (using.length() > 0 && Character.isDigit(using.charAt(0))) {
using = "\\" + Integer.toString(30 + Integer.parseInt(using.substring(0,1))) + " " + using.substring(1);
}
return using;
}
Hence you see the - character being escaped by the \ character.
I will answer my own question since I've found the solution.
I added a wait before finding the element.
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.
PresenceOfAllElementsLocatedBy(By.Id("btn-GDR")));
Turns out that sometimes the element is not present for some strange reason.. I can see it on screen but it takes 2-3 secs for Selenium to properly being able to interact with it. Yes, the element is always visible, enabled and it does exits. Also, when reporting the options Selenium reports adds the backslash before the hyphen to the output message.
FYI I've found the same case here. It was unanswered.
Similar Problem
I am trying to retrieve an object out of my MongoDB instance. I am using the JsonCPP library.
Currently, what I am doing is:
system(("mongo --host " + host_name + " --port " + std::to_string(port) + " " + database_name + " --eval 'db." + collection_name + ".find({},{_id:0})' | tee -a return_from_db.json").c_str());
And parsing it later on using:
Json::Value json_object;
Json::Reader jsonreader.parse(ifstream_from_return_from_db_json, json_object, false);
As soon as I am not suppressing the _id field in my query, I'll get null values everywhere. The reason for this is as follows:
{
"_id": ObjectId("any_id")
}
The object ID is not in double quotes.
Now my question: How can I extract the ID of a document using the jsoncpp library? Can I change something in the settings of my MongoDB instance to get syntactically correct id key-value mappings?
I know, there is the MongoDB driver for CPP, but I cannot use it (for a couple of reasons...). Any help appreciated.
The MongoDB shell only looks like JSON. It provides a custom, extended form to preserve type information not available in pure JSON, so your approach won't work for any document projection that includes such types.
You can read more about it in the Extended JSON docs (see "Shell mode").
If you can't use a driver, you might want to explore a third party REST interface instead.
I need to extract a username from the log below via regex for a log collector.
Due to the nature of the logs we're getting its not possible to define exactly how many forward slashes are going to be available and I need to select a specific piece of data, as there are multiple occurances of similar formatted data.
Required data:
name="performedby" label="Performed By" value="blah.com/blah/blah blah/blah/**USERNAME**"|
<46>Jun 23 10:38:49 10.51.200.76 25113 LOGbinder EX|3.1|success|2016-06-23T10:38:49.0000000-05:00|Add-MailboxPermission Exchange cmdlet issued|name="occurred" label="Occurred" value="6/23/2016 10:38:49 AM"|name="cmdlet" label="Cmdlet" value="Add-MailboxPermission"|name="performedby" label="Performed By" value="blah.com/blah/blah blah/blah/USERNAME"|name="succeeded" label="Succeeded" value="Yes"|name="error" label="Error" value="None"|name="originatingserver label="Originating Server" value="black"|name="objectmodified" label="Object Modified" value="blah/blah/USERNAME"|name="parameters" label="Parameters" value="Name: Identity, Value: [blah]Name: User, Value: [blah/blah]Name AccessRights, Value: [FullAccess]Name: InheritanceType, Value: [All]"|name="properties" label="Modified Properties" value="n/a"|name="additionalinfo" label="Additional Information"
I've tried a few different regex commands but I'm not able to extract the necessary information without exactly stating how many / there will be.
blah\.com[.*\/](.*?)"\|name
Try this :
blah\.com.*\/(.*?)"\|
Check here
If your username format is this :
value="abc.xyz/something/something/..../USERNAME"
then use this :
\..*\/(.*?)"
check here
Possible solution:
value="[a-z\.\/]*\/(.*)"
(The first capture group is the username)
Working example:
https://regex101.com/r/qZ0zC8/2
Mayby like this?
blah.(\w+\/)+\K([\w]+)
It's catch Username but since it's between ** so I also match them
tested in notepad++
I want to retrieve all links from the page, where link text is in the below format.
(10) Now I tried using below method but it didn't work.
There are many similar links available on the same page where number is not in sequence and also there are many repeated numbers for the link text, so I want to first collect such web element and then using attribute I can get the URL.
Similar to this page.
http://www.dmoz.org/search?q=surat&start=0&type=more&all=no&cat=
I want the link after we click on those numbers present in the bracket.
List<WebElement> catLinks = driver.findElements(By.xpath("//html/body/div[#id='doc']/div[#id='bd-cross']/ol/li[1]/a[2]"));
for (WebElement catLink : catLinks) {
System.out.println(nLink + ". " + catLink.getAttribute("href"));
}
Link XPath is:
//html/body/div[#id='doc']/div[#id='bd-cross']/ol/li[***1***]/a[2]
Using Above XPath I can get the first link URL. Now What I can do to get all links URL.
I tried using regexp :
//html/body/div[#id='doc']/div[#id='bd-cross']/ol/li[\\d\\.\\*]/a[2]
But it is not working.
I also tried using below method.
List<WebElement> catLinks = driver.findElements(By.linkText("\\d\.\*"));
for (WebElement catLink : catLinks) {
System.out.println(nLink + ". " + catLink.getAttribute("href"));
}
but no luck.
Now What I can do to get all links
URL.
I triedn using regex :
//html/body/div[#id='doc']/div[#id='bd-cross']/ol/li[\\d\\.\\*]/a[2]
Nop. Use:
/html/body/div[#id='doc']/div[#id='bd-cross']/ol/li/a[2]
Less is more.
You don't need to include the /html/body/ in the xpath locator, this will just make it more fragile if the page structure changes. Try this much simpler xpath locator: id('bd-cross')//li/a[2]