Tôi đang trích xuất một chuỗi và cần kiểm tra xem nó có tuân theo một mẫu cụ thể không Show
Nếu vậy tôi cần thay thế nó bằng "". Tôi đang thử mã sau
Nhưng tôi đang nhận được đầu ra là
Tôi muốn có được đầu ra như xin chào. Tôi làm gì sai ở đây?
cs95 347K87 Huy hiệu vàng638 Huy hiệu bạc685 Huy hiệu Đồng87 gold badges638 silver badges685 bronze badges hỏi ngày 26 tháng 7 năm 2017 lúc 11:41Jul 26, 2017 at 11:41
0
Là một sự đơn giản hóa (lịch sự Wiktor Stribiżew), bạn có thể thoát khỏi paren đầu trái đầu tiên, rút ngắn Regex của bạn thành Đã trả lời ngày 26 tháng 7 năm 2017 lúc 11:43Jul 26, 2017 at 11:43
cs95cs95cs95 347K87 Huy hiệu vàng638 Huy hiệu bạc685 Huy hiệu Đồng87 gold badges638 silver badges685 bronze badges 1 Xem thảo luận Cải thiện bài viết Lưu bài viết Xem thảo luận Cải thiện bài viết Lưu bài viết Đọc Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted Bàn luận Make a regular expression(regex) object of all the special characters that we don’t want, then pass a string in search method. If any one character of string is matching with regex object then search method returns a match object otherwise return None. C++ 0 1Đưa ra một chuỗi, tác vụ là kiểm tra xem chuỗi đó có chứa bất kỳ ký tự đặc biệt nào không (bộ ký tự đặc biệt được xác định). Nếu bất kỳ ký tự đặc biệt nào được tìm thấy, don don chấp nhận chuỗi.Examples đó: & nbsp; & nbsp; Cách tiếp cận: Tạo đối tượng biểu thức thông thường (Regex) của tất cả các ký tự đặc biệt mà chúng tôi không muốn, sau đó chuyển một chuỗi trong phương thức tìm kiếm. Nếu bất kỳ một ký tự nào của chuỗi phù hợp với đối tượng Regex thì phương thức tìm kiếm sẽ trả về một đối tượng khớp nếu không trả về không. 7 8 9 0 1 8 3 4 5 6 7 8 8Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted0 5 6Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted3 8Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted5 2 3 4 7 8String is not accepted.0 String is not accepted.1 8 8String is not accepted.4 5 6Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted5 Python3Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted6 Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted7 8String is not accepted.6 String is not accepted.7 String is not accepted.9 string is not accepted0 string is not accepted1 string is not accepted2 5<![any word]> 9string is not accepted8 7<![any word]> 0 8Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted0 [ 5 5<![any word]> 9string is not accepted8 Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted3 <![any word]> 0 8string is not accepted4 string is not accepted5 string is not accepted6 string is not accepted7 string is not accepted8 string is not accepted9 <![any word]> 0Các 8"<!\[.*?]>" 2In [1]: re.sub(re.compile("<!\[.*?\]>"), "", "<![if support]> hello") Out[1]: ' hello' 3 ]2string is not accepted55____55 ]5 [5
8] 8string is not accepted5 String is not accepted.1 7PHP 04"<!\[.*?]>" 6 1 8 3string is not accepted8 00<![any word]> 0 5<![any word]> 9string is not accepted8 7 1 8Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted0 5<![any word]> 9string is not accepted8 Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted3 1Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted5
1 32
String is not accepted.
C++ 0 34Đưa ra một chuỗi, tác vụ là kiểm tra xem chuỗi đó có chứa bất kỳ ký tự đặc biệt nào không (bộ ký tự đặc biệt được xác định). Nếu bất kỳ ký tự đặc biệt nào được tìm thấy, don don chấp nhận chuỗi.Examples đó: & nbsp; & nbsp; Cách tiếp cận: Tạo đối tượng biểu thức thông thường (Regex) của tất cả các ký tự đặc biệt mà chúng tôi không muốn, sau đó chuyển một chuỗi trong phương thức tìm kiếm. Nếu bất kỳ một ký tự nào của chuỗi phù hợp với đối tượng Regex thì phương thức tìm kiếm sẽ trả về một đối tượng khớp nếu không trả về không. 2 3 4 5 6 40 48 49 50Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted6 Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted7 40 7 8String is not accepted.6 String is not accepted.7 8 7 63 64 8Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted5 40Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted5 40 3 71String is not accepted.9 string is not accepted0 40Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted5 40Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted0 7 8 6 83 8 40Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted5 5 6Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted6 Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted7 Python3 91string is not accepted5 String is not accepted.1 94 95string is not accepted5 97 8String is not accepted.6 String is not accepted.7 String is not accepted.9 string is not accepted0 string is not accepted1 string is not accepted2 8string is not accepted4 string is not accepted5 string is not accepted6 string is not accepted7 string is not accepted8 string is not accepted9 <![any word]> 0Các 8<![any word]> 9string is not accepted8 74<![any word]> 0Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted0 [ 5 8<![any word]> 9string is not accepted8 32<![any word]> 0
string is not accepted Làm thế nào để tôi tìm thấy các nhân vật đặc biệt trong Python?Phương thức: Để kiểm tra xem một ký tự đặc biệt có mặt trong một chuỗi nhất định hay không, trước tiên nhóm tất cả các ký tự đặc biệt là một tập hợp. Sau đó sử dụng cho vòng lặp và nếu các câu lệnh kiểm tra các ký tự đặc biệt.Nếu bất kỳ ký tự đặc biệt nào được tìm thấy thì hãy tăng giá trị của c.firstly group all special characters as one set. Then using for loop and if statements check for special characters. If any special character is found then increment the value of c.
Làm thế nào để bạn tìm thấy các nhân vật đặc biệt?Để kiểm tra xem một chuỗi có chứa các ký tự đặc biệt không, hãy gọi phương thức Test () trên biểu thức chính quy phù hợp với bất kỳ ký tự đặc biệt nào.Phương thức kiểm tra sẽ trả về true nếu chuỗi chứa ít nhất 1 ký tự đặc biệt và sai.call the test() method on a regular expression that matches any special character. The test method will return true if the string contains at least 1 special character and false otherwise.
Là gì?: Trong regex?Nó chỉ ra rằng Subpattern là một tiểu đơn vị không bắt giữ.Điều đó có nghĩa là bất cứ điều gì được khớp trong (?indicates that the subpattern is a non-capture subpattern. That means whatever is matched in (?:\w+\s) , even though it's enclosed by () it won't appear in the list of matches, only (\w+) will.
Làm thế nào để bạn thoát khỏi các nhân vật đặc biệt trong Regex Python?Thoát ra với \ để phù hợp với các metacharacters theo nghĩa đen, tức là để loại bỏ ý nghĩa đặc biệt của chúng, tiền tố các ký tự đó có ký tự \ (dấu gạch chéo ngược).Để chỉ ra một ký tự \ theo nghĩa đen, hãy sử dụng \\.prefix those characters with a \ (backslash) character. To indicate a literal \ character, use \\ . |