I need a regular expression to replace a syntax - sublimetext3

I am new to sublime text3 but started to like working in it.
I am using its search and replace to achieve as below:
I have a list of hundreds of items like the below :
5149 : Kaliana
5427 : Kalo Chorio
5036 : Kalo Chorio Kapouti
5071 : Kalo Chorio Sleas
5466 : Kalopanagiotis
But I want to replace these with
5149-
5427-
5036-
5071-
5466-
So basically the colon and the words should be replaced by a hyphen(-) symbol
I tried few regular expressions.
for example : (?<=WORD).*$
but things aren't working.

I tried myself and finally got the expression that works for my requirement.
In the find area type:
: [a-zA-Z\d" "]+
And in the replace area type:
-
This gives you the numbers followed by a hiphen and eliminating the words.

Related

When I try to build the FNF Kade Engine's source code it won't work (lime test and build wise)

C:\HaxeToolkit\haxe\std/eval/_std/haxe/Exception.hx:39: characters 4-53 : Array<haxe.StackItem> should be haxe.CallStack
C:\HaxeToolkit\haxe\std/eval/_std/haxe/Exception.hx:42: characters 4-48 : Array<haxe.StackItem> should be haxe.CallStack
C:\HaxeToolkit\haxe\std/eval/_std/haxe/Exception.hx:57: characters 27-44 : Class<haxe.CallStack> has no field exceptionToString
C:\HaxeToolkit\haxe\std/eval/_std/haxe/Exception.hx:82: characters 20-27 : haxe.CallStack has no field asArray
C:\HaxeToolkit\haxe\std/eval/_std/haxe/Exception.hx:4: lines 4-89 : Field stack has different type than in core type
C:\HaxeToolkit\haxe\std/eval/_std/haxe/Exception.hx:4: lines 4-89 : haxe.CallStack should be haxe.CallStack
export/release/windows/haxe/ApplicationMain.hx:298: characters 1-8 : Build failure
It creates the export folder but it's missing the exe.
How do I fix this?

How to search for a specific dynamic pattern of a field's in mongodb.?

I need to search mongodb collection for a specific pattern field. I tried using {$exists:true}; However, this gives results only if you provide exact field.
I tried using {$exists:true} for my field. But this does not give results if you give some pattern.
{
"field1":"value1",
"field2":"value2",
"field3":object
{/arjun1/pat1: 1,
/arjun2/pat2: 3,
/arjun3/pat3: 5
}
"field4":"value4",
}
From some field, I get the keys pat3 & field3. From this I would need to find out if the value /arjun3/pat3 exists in the document.
If I use {"field3./arjun3/pat3":{$exists:true}}, this would give me results. But the problem is I get only field3 and pat3 and I need to use some pattern matching like field3.*.pat3 and then use $expr or $exists; which I'm not exactly sure how to. Please help.
you could try something of this kind
db.arjun.find(
{"field3" : {
"$elemMatch" : { $and: [
{"arjun3.pat3" : {$exists:true}},
{"arjun3.pat3" : 5}
]
}}}
);
You can either go for regex (re module) for SQL like pattern matching, and compile your own custom wildcard. But if you don't want that then you can simple use the fnmatch module, it is a builtin library of python which allows wildcard matching for multiple characters (via*) or a single character (via ?).
import fnmatch
a = "hello"
print(fnmatch.fnmatch(a, "h*"))
OUTPUT:-
True

How can I search the special characters in Solr

I'm used Solr 6.6.2
I need to search the special characters and highlight it in Solr,
But it does not work,
my data :
[
{
"id" : "test1",
"title" : "test1# title C# ",
"dynamic_s": 5
},
{
"id" : "test2",
"title" : "test2 title C#",
"dynamic_s": 10
},
{
"id" : "test3",
"title" : "test3 title",
"dynamic_s": 0
}
]
When I search "C#",
Then it will just response like this "test1# title C# ",
It just highlights "C" this word...and "#" will not searching and highlight.
How can I make the search and highlight work for special characters?
The StandardTokenizer splits tokens on special characters, meaning that # will split the content into separate tokens - the first token will be C - and that's what's being highlighted. You'll probably get the exact same result if you just search for C.
The tokenization process will make your tokens end up being test2 title C .
Using a field type with a WhitespaceTokenizer that only splits on whitespace will probably be a better choice for this exact use case, but it's impossible to say if that'll be a good match for your regular search behavior (i.e. if you actually want to match 'C' to `C-99' etc., splitting by those characters can be needed). But - you can use a specific field for highlighting, and that fields analysis chain will be used to determine what to highlight. And you can ask for both the original and the more specific field to be highlighted, and then use the best result in your frontend application.

How to replace part of a string with an added condition

The problem:
The objective is to convert: "tan(x)*arctan(x)"
Into: "np.tan(x)*np.arctan(x)"
What I've tried:
s = "tan(x)*arctan(x)"
s = s.replace('tan','np.tan')
Out: np.tan(x)*arcnp.tan(x)
However, using pythons replace method resulted in arcnp.tan.
Taking one additional step:
s = s.replace('arcnp.', 'np.arc')
Out: np.tan(x)*np.arctan(x)
Achieves the desired result... but this solution is sloppy and inefficient.
Is there a more efficient solution to this problem?
Any help is appreciated. Thanks in advance.
Here is a way to do the job:
var string = 'tan(x)*arctan(x)';
var res = string.replace(/\b(?:arc)?tan\b/g,'np.$&');
console.log(res);
Explanation:
/ : regex delimiter
\b : word boundary, make sure we don't have any word character before
(?:arc)? : non capture group, literally 'arc', optional
tan : literally 'tan'
\b : word boundary, make sure we don't have any word character after
/g : regex delimiter, global flag
Replace:
$& : means the whole match, ie. tan or arctan
You can use regular expression to solve your issue. Following code is in javascript. Since, u didn't mention the language you are using.
var string = 'tan(x)*arctan(x)*xxxtan(x)';
console.log(string.replace(/([a-z]+)?(tan)/g,'np.$1$2'));

How do we replace spaces with dashes in a permalink that Autoroute generates from a pattern?

I would like to generate the following URL for a 'My Type' content type.
mywebsite.com/my-type/some-item
I have tried the following patterns:
{Content.ContentType}/{Content.Slug} : My Type/some-item
{Content.ContentType.Slug}/{Content.Slug} : some-item
{Content.ContentType.Text.Slug}/{Content.Slug} : some-item
{Text.Slug}{Content.ContentType}/{Content.Slug} : My Type/some-item

Resources