special-characters

How to change ajax-charset?

笑着哭i 提交于 2019-11-26 16:44:23
问题 How can I change the default encoding used by $.post() ? The arguments are encoded with UTF-8. How can I encode it with ISO 8859-1? 回答1: You could use: contentType:"application/x-javascript; charset:ISO-8859-1" 回答2: By giving the content type explicitly during ajax call as below may allow you to override the default content type. $.ajax({ data: parameters, type: "POST", url: ajax_url, timeout: 20000, contentType: "application/x-www-form-urlencoded;charset=ISO-8859-15", dataType: 'json',

How to escape a square bracket for Pattern compilation

拟墨画扇 提交于 2019-11-26 16:39:56
问题 I have comma separated list of regular expressions: .{8},[0-9],[^0-9A-Za-z ],[A-Z],[a-z] I have done a split on the comma. Now I'm trying to match this regex against a generated password. The problem is that Pattern.compile does not like square brackets that is not escaped. Can some please give me a simple function that takes a string like so: [0-9] and returns the escaped string \[0-9\] . 回答1: You can use Pattern.quote(String). From the docs: public static String quote​(String s) Returns a

Java- Extract part of a string between two special characters

自古美人都是妖i 提交于 2019-11-26 16:14:49
问题 I have been trying to figure out how to extract a portion of a string between two special characters ' and " I've been looking into regex, but frankly I cannot understand it. Example in Java code: String str="21*90'89\""; I would like to pull out 89 In general I would just like to know how to extract part of a string between two specific characters please. Also it would be nice to know how to extract part of the string from the beginning to a specific character like to get 21. 回答1: Try this

Remove all special characters except space from a string using JavaScript

℡╲_俬逩灬. 提交于 2019-11-26 15:53:10
I want to remove all special characters except space from a string using JavaScript. For example, abc's test#s should output as abcs tests . You should use the string replace function, with a single regex. Assuming by special characters, you mean anything that's not letter, here is a solution: var str = "abc's test#s"; alert(str.replace(/[^a-zA-Z ]/g, "")); Lakshmana Kumar D You can do it specifying the characters you want to remove: string = string.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, ''); Alternatively, to change all characters except numbers and letters, try: string = string.replace(/[^a

How to detect line breaks in a text area input?

◇◆丶佛笑我妖孽 提交于 2019-11-26 15:40:05
问题 What is the best way to check the text area value for line breaks and then calculate the number of occurrences, if any? I have a text area on a form on my webpage. I am using JavaScript to grab the value of the text area and then checking its length. Example enteredText = textareaVariableName.val(); characterCount = enteredText.length; // One line break entered returns 1 If a user enters a line break in the text area my calculation above gives the line break a length of 1. However I need to

Post UTF-8 encoded data to server loses certain characters

ⅰ亾dé卋堺 提交于 2019-11-26 15:31:39
问题 I am working on project which includes communication of the server (JavaEE app) and client (Android app). XML is sent as one of POST parameters of the HTTP request (named "xml"). There are also few other POST parameters which I pass to server, but in function below I removed them for simplicity. Problem that occurs is that certain letters are not properly delivered to the server - for example character Ű (Note that this is not German Ü , which is properly delivered, by the way). Code for

jQuery: Check if special characters exists in string

隐身守侯 提交于 2019-11-26 15:26:02
问题 I know this question is asked more often here on Stack, but I can't seem to get a straight answer out of the questions already posted. I need to check if all special characters (except -) are in a string, if so, then give the user an alert. What I have so far is this: if($('#Search').val().indexOf('@') == -1 || $('#Search').val().indexOf('#') == -1 || $('#Search').val().indexOf('$') == -1 || $('#Search').val().indexOf('%') == -1 || $('#Search').val().indexOf('^') == -1 || $('#Search').val()

Check if a String contains a special character

这一生的挚爱 提交于 2019-11-26 15:18:01
How do you check if a String contains a special character like: [,],{,},{,),*,|,:,>, r3zn1k Pattern p = Pattern.compile("[^a-z0-9 ]", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher("I am a string"); boolean b = m.find(); if (b) System.out.println("There is a special character in my string"); Ashish Sharma You can use the following code to detect special character from string. import java.util.regex.Matcher; import java.util.regex.Pattern; public class DetectSpecial{ public int getSpecialCharacterCount(String s) { if (s == null || s.trim().isEmpty()) { System.out.println("Incorrect format of

How to escape dollar sign ($) in a string using perl regex

瘦欲@ 提交于 2019-11-26 14:48:53
问题 I'm trying to escape several special characters in a given string using perl regex. It works fine for all characters except for the dollar sign. I tried the following: my %special_characters; $special_characters{"_"} = "\\_"; $special_characters{"$"} = "\\$"; $special_characters{"{"} = "\\{"; $special_characters{"}"} = "\\}"; $special_characters{"#"} = "\\#"; $special_characters{"%"} = "\\%"; $special_characters{"&"} = "\\&"; my $string = '$foobar'; foreach my $char (keys %special_characters)

How to ignore acute accent in a javascript regex match?

荒凉一梦 提交于 2019-11-26 14:48:31
问题 I need to match a word like 'César' for a regex like this /^cesar/i . Is there an option like /i to configure the regex so it ignores the acute accents?. Or the only solution is to use a regex like this /^césar/i . 回答1: The standard ecmascript regex isn't ready for unicode (see http://blog.stevenlevithan.com/archives/javascript-regex-and-unicode). So you have to use an external regex library. I used this one (with the unicode plugin) in the past : http://xregexp.com/ In your case, you may